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).

2 Answers 2

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() 
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, I don't understand. You mean Axes3D is different from axes3d? Btw, I have imported Axes3D as well.
@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?
@Py-ser Sorry, but I can't help you there, since I don't see your code.
This works for me. @Py-ser maybe providing a minimal working example in your question would help?
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.