2

How can I turn the label of the axes on a 3D plot from this:

(Labels "perpendicular" to the axes)

enter image description here

To this: (Labels "parallel" to the axes)

enter image description here Perhaps, with the Y label in this case turned of 90 degree.

I simply use ax.set_xlabel('X axis'), and respective, for each of the three axis, but the labels result perpendicular, and occupy a substantial part of the plot.

I was reading this discussion, but it is actually not answered, and the get module I don't know where it comes from (I receive error if I try that solution).

Community
  • 1
  • 1
Py-ser
  • 1,860
  • 9
  • 32
  • 58

2 Answers2

2

I am guessing that you imported axes3d module. Because it seems from looking at the matplotlib gallery examples, that the default behaviour of axes3d is to have labels "perpendicular", as on your first plot. But the module Axes3D have default labels to be "parallel" to the axes, as on your second plot.

As for discussion you linked, it applies to matplab and not to matplotlib.

Here is a code that should work for you:

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

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

points = np.random.rand(3, 40)

ax.scatter(points[0], points[1], points[2])

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()
jure
  • 402
  • 5
  • 9
  • 1
    Sorry, I don't understand. You mean `Axes3D` is different from `axes3d`? Btw, I have imported `Axes3D` as well. – Py-ser Jul 18 '14 at 07:45
  • @Py-ser: I don't know about the inner workings, but as I saw from examples provided in their gallery, it seems that they behave differently. Have you tried the above code? – jure Jul 18 '14 at 08:04
  • @Py-ser Sorry, but I can't help you there, since I don't see your code. – jure Jul 20 '14 at 11:23
  • This works for me. @Py-ser maybe providing a [minimal working example](http://stackoverflow.com/help/mcve) in your question would help? – Schorsch Aug 11 '14 at 12:08
0

I have found the following as the best workaround:

ax.zaxis.set_rotate_label(False) # To disable automatic label rotation

ax.set_ylabel('Y')
ax.set_xlabel('X', rotation=-90)
ax.set_zlabel('Z', rotation=90)

From here.

Community
  • 1
  • 1
Py-ser
  • 1,860
  • 9
  • 32
  • 58