【发布时间】:2013-12-04 14:09:36
【问题描述】:
diff = [[10,20,30],[40,50,60],[70,80,90]]
comp = ["foo","bar","baz"]
fig,ax = plt.subplots()
for foo in range(0, len(diff)):
x = [diff[foo]]
name = comp
color = ['0.1', '0.2', '0.3']
label = ['1000000','1200000', '1400000']
y = zip(*x)
pos = np.arange(len(x))
width = 1. / (1 + len(x))
fig = plt.subplot(3,1,foo)
for idx, (serie, color,label) in enumerate(zip(y, color,label)):
ax.bar(pos + idx * width, serie, width, color=color,label=label)
fig = plt.gcf()
fig.set_size_inches(28.5,10.5)
ax.set_xticks(pos + 1.5*width)
plt.ylabel(name[foo])
ax.set_xticklabels(comp)
ax.legend()
plt.gray()
plt.savefig("file" + '.jpg', bbox_inches='tight', pad_inches=0.5,dpi=100)
plt.clf()
我想对foo bar and baz 进行子图。但是当我尝试使用上面的代码来做到这一点时。数据未显示在图表上。知道为什么吗?
【问题讨论】:
-
我发现了一个非常讨厌的快捷方式,我不喜欢它。使用
Montage加入图像。 :) 像这样montage -geometry 500 image1 image2 [...] output -
你已经调用了两次
subplots:一次在没有参数的循环之前,它创建了一个只有一个轴的图形,但是在循环中你再次调用它(3,1, ...)你想要将第二个调用移到顶部,然后在三个轴中的每一个中绘制一次。
标签: python matplotlib histogram subplot