我试图用Matplotlib显示一个绘图,使用一个.txt文件中的数组数据,但是当显示该数字时,没有绘图,并且标签重复了数字阵列的位置。发生了什么?matplotlib错误。不要显示阴谋
前奏数据文件是这样的:
0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0, 1.0,1.0,1.0,1.0,1.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,25.0,25.0,25.0,25.0,25.0, 25.0,25.0,25.0,25.0,25.0
然后告诉我这个阴谋:
这就是代码:
import matplotlib.pyplot as plt
import codecs
converted = []
reward = open('reward_5_clusters','r')
acum = reward.readlines()
for line in acum:
if line.startswith(codecs.BOM_UTF8):
line = line[len(codecs.BOM_UTF8):]
x = line.split(', ')
converted.append(x)
plt.plot(converted, label='5 clusters')
plt.ylabel('Reward')
plt.xlabel('Time')
plt.title('Cumulative Reward')
plt.grid(True)
plt.legend(loc=0)
plt.show(block=False)
plt.savefig('cumulative_reward.png')
如何解决这一问题?
非常感谢,这解决了我! –