import pylab 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])
a = plt.subplot(1,2,1)
test(a)
b = plt.subplot(1,2,2)
test(b)
我期待的xlabs为101, 102 ...
但是,如果我切换使用plt.xticks(x, [i+100 for i in x])
,并明确重写的功能,它的工作原理。
我的猜测是因为在你的代码set_xticks越来越发电机对象,而不是一个列表。试试'list([i + 100 for i in x)]'而不是。 – rabs
@rabs没有涉及生成器,它们都是列表,我正在使用python 2 – colinfang