2014-02-20 2 views
13

z- 레이블을 회전시켜 텍스트가 (top => bottom)이 아닌 (bottom => top)되도록하려면 어떻게합니까? 3D matplotlib에서 축 레이블 텍스트 회전하기

enter image description here

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

나는이에 상관없이 내 ax.azim 설정이 무엇 유지하지 싶습니다. 이것은 old feature request on github 인 것 같지만 거기에 대한 연구는 없습니다. 해결 방법이 있습니까?

+1

답을 알고 싶습니다. –

답변

14

는 해결 방법으로 수동으로 Z-라벨의 방향을 설정할 수 있습니다 :

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

이 Z-라벨의 방향도, 당신의 관점에 달려 있습니다 예 :

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

enter image description here

업데이트를 제공 :이 또한 가능하다 플롯의 Z 라벨 방향을 조정할 이미 그려져있다. 다음은 라벨을 수정 한 수정 버전입니다.

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