我正在使用Matplotlib绘制浮点数列表的图表。如果我的列表长度为100个浮点数,图表会显示正确的颜色。但是如果列表长度为785个浮点数,则只会显示黑色。以下是代码。
import numpy as np
import matplotlib.pyplot as plt
import Image
Consensus = []
Prediction = []
Final = []
for line in open('1.out').readlines():
words = line.split()
Consensus.append(float(words[10]))
Prediction.append(int(words[11]))
for i,j in zip(Consensus,Prediction):
Final.append(i*j)
max_score = 3
length = 785
ind = np.arange(length) # the x locations for the groups
width = 1 # the width of the bars: can also be len(x) sequence
p1 = plt.bar(ind, Consensus, width, color='red')
p2 = plt.bar(ind, Final, width, color='blue')
plt.ylabel('Scores')
plt.title('Scores by group and gender')
plt.xticks(np.arange(0,length,50))
plt.yticks(np.arange(0,max_score,0.2))
plt.savefig('testplot.png')
Image.open('testplot.png').save('testplot.jpg','JPEG')
这是当列表长度为785时程序的图片。
![这是当列表长度为785时程序的图片。](https://istack.dev59.com/htvQN.webp)
![这是列表长度为99时的情况。](https://istack.dev59.com/00S3i.webp)
谢谢。