2014-02-20 2 views
13

Как повернуть z-метку, чтобы текст читал (снизу => верх), а не (top => внизу)?Поворот осей на этикетке текста в 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

Я хочу, чтобы это не держать независимо от того, что моя ax.azim установка. Кажется, это old feature request on github, но на нем нет работы. Есть ли обходной путь?

+1

Интересует также ответ. –

ответ

14

В качестве временного решения можно установить направление г-метки вручную:

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

Пожалуйста, обратите внимание, что направление вашей г-метки, также зависит от вашей точки зрения, например:

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

Update: также возможно, регулировать направление г-маркированной участка, который уже нарисован (но не заранее). Это скорректированная версия для изменения этикеток:

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() 
Смежные вопросы