我刚刚开始使用“matplotlib”,并且遇到了 2 个主要障碍,我似乎无法从文档/示例等中解决:这是 Python 源代码:
#!/usr/bin/python
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
for i in range(0,301):
print "Plotting",i
# Reading a single column data file
l=plt.plotfile("gen"+str(i))
plt.xlabel('Population')
plt.ylabel('Function Value')
plt.title('Generation'+str(i))
plt.axis([0,500,0,180])
plt.plot()
if len(str(i)) == 1:
plt.savefig("../images/plot00"+str(i)+".png")
if len(str(i)) == 2:
plt.savefig("../images/plot0"+str(i)+".png")
if len(str(i)) == 3:
plt.savefig("../images/plot"+str(i)+".png")
plt.clf()
- 疑点一:如你所见,我基本上是清空剧情,然后每次都保存新剧情。我想保持 Y 轴的范围不变,我试图通过“plt.axis([0,500,0,180])”来做到这一点。但它似乎不起作用,并且每次都会自动设置。
- 疑问2:我宁愿获得一个“*”的图,而不是获得点由连续线连接的默认图。我该怎么做?