【发布时间】:2018-04-05 22:34:03
【问题描述】:
我正在尝试绘制 n 个直方图并将它们并排显示(不在同一个直方图中。
我试过这段代码:
for r in range(1, n):
plt.hist(combined['apple{} tomato'.format(n)], bins = bin, alpha=0.5, color='#0bf9ea')
plt.hist(combined['apple{} potato'.format(n)], bins = bin, alpha=0.5, color='#ff7fa7')
plt.show()
当我输入此代码时,它会显示直方图 1,然后当我关闭图形时,会出现直方图 2,依此类推,直到直方图 n。
for r in range(1, n):
plt.hist(combined['apple{} tomato'.format(n)], bins = bin, alpha=0.5, color='#0bf9ea')
plt.hist(combined['apple{} potato'.format(n)], bins = bin, alpha=0.5, color='#ff7fa7')
plt.show()
但是,当我尝试此代码时,它会显示一个直方图,其中包含所有直方图。
有没有办法在一个窗口中分别显示所有 n 个不同的直方图?
谢谢 :D
【问题讨论】:
-
感谢@Brad Solomon,这对我帮助很大!
标签: python matplotlib