属性错误:未知属性tick_lab

2024-04-23 10:26:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我只想做一个柱状图,我可以自己画横坐标。在

import matplotlib.pyplot as plt
heros=['Mage','Priest','Warlock']
y=[0.1828, 0.1300, 0.0689]

x = range(len(heros))
plt.bar(range(len(y)), y,color=['g'],tick_label=heros)
plt.show()

但我有个错误---- AttributeError:未知属性勾选标签


Tags: importlenmatplotlibasbarrangepltcolor
1条回答
网友
1楼 · 发布于 2024-04-23 10:26:51

您可能使用的是相当旧的Matplotlib版本(2015年11月之前)。tick_label参数是added to ^{} in 1.5.0this commit。在

更新到更新的版本(2.1现在是发布候选状态!)或者通过修改轴的记号标签手动重写记号。1.4及之前的示例here,节选如下:

# Example data
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))

plt.barh(y_pos, performance, align='center', alpha=0.4)
plt.yticks(y_pos, people)

相关问题 更多 >