2014-02-20 7 views
13

Wie drehe ich das Z-Label, so dass der Text liest (unten => oben) und nicht (oben => unten)?Rotierende Achsen Etikettentext in 3D matplotlib

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

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
ax.set_zlabel('label text flipped', rotation=90) 
ax.azim = 225 
plt.show() 

enter image description here

Ich möchte dies egal halten, was meine ax.azim Einstellung. Dies scheint ein old feature request on github zu sein, aber es gibt keine Arbeit daran. Gibt es eine Problemumgehung?

+1

Interessiert, um die Antwort auch zu kennen. –

Antwort

14

Als Abhilfe können, können Sie die Richtung der z-Etikett manuell eingestellt von:

ax.zaxis.set_rotate_label(False) # disable automatic rotation 
ax.set_zlabel('label text', rotation=90) 

Bitte beachten Sie, dass die Richtung Ihrer z-Etikett hängt auch von Ihrer Sicht, zum Beispiel:

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

fg = plt.figure(1); fg.clf() 
axx = [fg.add_subplot(4,1,1+i, projection='3d') for i in range(4)] 
for ax,azel in zip(axx, [(115,10), (115,-10), (-115,10), (-115,-10)]): 
    ax.set_title(u"Azim, elev = {}°, {}°".format(*azel)) 
    ax.set_zlabel('label text') 
    ax.azim, ax.elev = azel 

fg.canvas.draw() 
plt.show() 

gibt enter image description here

Update: Es ist auch möglich, die z-Label Richtung einer Handlung anzupassen, das ist schon gezeichnet (aber nicht vorher). Dies ist die angepasste Version zum Ändern der Bezeichnungen:

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

fg = plt.figure(1); fg.clf() 
axx = [fg.add_subplot(4,1,1+i, projection='3d') for i in range(4)] 
for ax,azel in zip(axx, [(115,10), (115,-10), (-115,10), (-115,-10)]): 
    ax.set_title(u"Azim, elev = {}°, {}°".format(*azel)) 
    ax.set_zlabel('label text') 
    ax.azim, ax.elev = azel 
fg.canvas.draw() # the angles of the text are calculated here 

# Read drawn z-label rotations and switch them if needed 
for ax in axx: 
    ax.zaxis.set_rotate_label(False) 
    a = ax.zaxis.label.get_rotation() 
    if a<180: 
     a += 180 
    ax.zaxis.label.set_rotation(a) 
    a = ax.zaxis.label.get_rotation() # put the actual angle in the z-label 
    ax.set_zlabel(u'z-rot = {:.1f}°'.format(a)) 
fg.canvas.draw() 

plt.show()