我在同时画两个图形时遇到了一些麻烦,没有在一个图中显示出来。但是根据文档,我编写了代码,只有图1显示。我想也许我失去了一些重要的东西。有谁能帮我弄清楚吗?谢谢。(代码中使用的*tlist_first*是一个数据列表。)
plt.figure(1)
plt.hist(tlist_first, bins=2000000, normed = True, histtype ="step", cumulative = True, color = 'g',label = 'first answer')
plt.ylabel('Percentage of answered questions')
plt.xlabel('Minutes elapsed after questions are posted')
plt.axvline(x = 30, ymin = 0, ymax = 1, color = 'r', linestyle = '--', label = '30 min')
plt.axvline(x = 60, ymin = 0, ymax = 1, color = 'c', linestyle = '--', label = '1 hour')
plt.legend()
plt.xlim(0,120)
plt.ylim(0,1)
plt.show()
plt.close() ### not working either with this line or without it
plt.figure(2)
plt.hist(tlist_first, bins=2000000, normed = True, histtype ="step", cumulative = True, color = 'g',label = 'first answer')
plt.ylabel('Percentage of answered questions')
plt.xlabel('Minutes elapsed after questions are posted')
plt.axvline(x = 240, ymin = 0, ymax = 1, color = 'r', linestyle = '--', label = '30 min')
plt.axvline(x = 1440, ymin = 0, ymax = 1, color = 'c', linestyle = '--', label = '1 hour')
plt.legend(loc= 4)
plt.xlim(0,2640)
plt.ylim(0,1)
plt.show()
我也有同样的问题。
是否:
只在最后一个数字后写一次'plt.show()'。 为我工作。
除了在脚本末尾调用
plt.show()
之外,还可以分别控制每个图形执行以下操作:在这种情况下,您必须调用
raw_input
来保持图形的活动性。 这样可以动态选择要显示的图形注意:
raw_input()
在Python 3中被重命名为input()
只有在创建所有绘图之后,才应该在末尾调用
plt.show()
。相关问题 更多 >
编程相关推荐