import matplotlib.pyplot as plt
x = range(1, 7)
y = (220, 300, 300, 290, 320, 315)
def test(axes):
axes.bar(x, y)
axes.set_xticks(x, [i+100 for i in x])
fig, (ax1, ax2) = plt.subplots(1, 2)
test(ax1)
test(ax2)
我期待 xlabs101, 102 ...
但是,如果我切换到使用plt.xticks(x, [i+100 for i in x])
并显式重写该函数,它可以工作。
.set_xticks() http://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.set_xticks.html#matplotlib.axes.Axes.set_xticks轴上将设置位置并set_xticklabels() http://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.set_xticklabels.html#matplotlib.axes.Axes.set_xticklabels将设置显示的文本。
def test(axes):
axes.bar(x,y)
axes.set_xticks(x)
axes.set_xticklabels([i+100 for i in x])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)