我正在使用 Matplotlib 绘制 float 列表。如果我的列表有 100 个 float ,图表会显示正确的颜色。但是如果列表是 785 个 float 那么它只显示黑色。这是代码。
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时的程序图片。
这是列表长度为 99 时的情况。
文件可在此处获得 - http://pastebin.com/HhPhgPDG
您可以更改为仅复制此文件的前 100 行以检查其他情况。您应该将长度变量更改为文件中的行数。
谢谢。
最佳答案
条形图的边框是黑色的。有可能当你有这么多条形图时,它们会变得非常窄并且边界会挤在一起,所以你只能看到边界而看不到有颜色的内部。尝试放大图表以查看颜色是否存在。您还可以将 edgecolor='none'
参数传递给 bar
以删除边框。
关于python - Matplotlib - 为什么条形图线条颜色是黑色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12375478/