3

Since I usually try to label my axes in matplotlib plots, I find that I regularly label the x/y/z axes individually, using something like this:

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
# <plot plot plot>
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')     

Is there a way to reduce the individual axis-label setting to one command, ideally something like ax.set_labels(['x', 'y', 'z'])?

Felix
  • 2,064
  • 3
  • 21
  • 31
  • 1
    You could monkey-patch that in: http://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object-instance – cphlewis Feb 25 '16 at 08:51

1 Answers1

7

You can get close using ax.update. For example:

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')

ax.update({'xlabel':'x', 'ylabel':'y', 'zlabel':'z'})

From the docs for ax.update:

update(props)

Update the properties of this Artist from the dictionary prop.

So, you can update more than just axes labels using ax.update, so this could help reduce you code in other places too. Just pass whichever property to update in the dictionary. A list of available properties can be found using ax.properties()

tmdavison
  • 64,360
  • 12
  • 187
  • 165