Ann*_*neS 65 python matplotlib
我在同时绘制两个数字时遇到了一些麻烦,没有在一个图中显示.但根据文档,我编写了代码,只有图一显示.我想也许我失去了一些重要的东西.任何人都可以帮我搞清楚吗?谢谢.(代码中使用的*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()
Run Code Online (Sandbox Code Playgroud)
joa*_*uin 80
或者plt.show()在脚本结束时调用,您也可以分别控制每个数字:
f = plt.figure(1)
plt.hist........
............
f.show()
g = plt.figure(2)
plt.hist(........
................
g.show()
raw_input()
Run Code Online (Sandbox Code Playgroud)
在这种情况下,你必须打电话raw_input让数字保持活力.这样,您可以动态选择要显示的图形
注意:在Python 3中raw_input()重命名为input()
jan*_*neb 51
plt.show()在创建所有图之后,您应该只在结束时调用.
小智 12
我有同样的问题.
做的:
f1 = plt.figure(1)
# code for figure 1
# don't write 'plt.show()' here
f2 = plt.figure(2)
# code for figure 2
plt.show()
Run Code Online (Sandbox Code Playgroud)
#不要在这里写'plt.show()'
f1 = plt.figure(1)
# code for figure 1
# don't write 'plt.show()' here
f2 = plt.figure(2)
# code for figure 2
plt.show()
Run Code Online (Sandbox Code Playgroud)
在最后一个数字后面只写一次'plt.show()'.为我工作.
或者,我建议在开始时打开交互式,并在最后一个情节中将其关闭。全部都会出现,但它们不会消失,因为您的程序会一直存在,直到您关闭数字。
import matplotlib.pyplot as plt
from matplotlib import interactive
plt.figure(1)
... code to make figure (1)
interactive(True)
plt.show()
plt.figure(2)
... code to make figure (2)
plt.show()
plt.figure(3)
... code to make figure (3)
interactive(False)
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
151483 次 |
| 最近记录: |