【发布时间】:2010-12-02 00:41:09
【问题描述】:
如何在 Axes3D 中向坐标轴添加字符串而不是数字?
我刚开始使用 matplotlib。我使用 Axes3dD 绘制了类似于他们网站 (http://matplotlib.sourceforge.net/examples/mplot3d/bars3d_demo.html) 上给出的示例的绘图。请注意,必须使用最后一个版本(matplotlib 0.99.1),否则轴会有点怪异。该示例使用此代码:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = Axes3D(fig)
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
xs = np.arange(20)
ys = np.random.rand(20)
ax.bar(xs, ys, zs=z, zdir='y', color=c, alpha=0.8)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
现在我的问题是,我无法将轴重命名为我想要的。我需要将订书钉命名为字符串名称,而不是数字。这我只想在两个维度上做——x 维度和 z 维度(深度)。我试过用这个命令:
ax.set_xticklabels('First staple',(0,0))
我没有收到任何错误消息,但仍然没有刺痛。如果有人能回答这个问题,我将非常高兴!
【问题讨论】:
标签: python matplotlib