python - Matplotlib - 为什么条形图线条颜色是黑色?

标签 python colors matplotlib bar-chart

我正在使用 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时的程序图片。 This is the picture of the program when the list is 785 in length.

这是列表长度为 99 时的情况。 This is when the the list is 99 in length.

文件可在此处获得 - http://pastebin.com/HhPhgPDG

您可以更改为仅复制此文件的前 100 行以检查其他情况。您应该将长度变量更改为文件中的行数。

谢谢。

最佳答案

条形图的边框是黑色的。有可能当你有这么多条形图时,它们会变得非常窄并且边界会挤在一起,所以你只能看到边界而看不到有颜色的内部。尝试放大图表以查看颜色是否存在。您还可以将 edgecolor='none' 参数传递给 bar 以删除边框。

关于python - Matplotlib - 为什么条形图线条颜色是黑色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12375478/

相关文章:

python - 从 python 函数返回 dict 项

python - input() 和 sys.stdin 有什么区别?

python - 在 tensorflow 中输入图像数据以进行迁移学习

python - @property touch 有什么神奇的方法

java - 如何让重叠的形状产生新的颜色?

python - 添加 X 轴上方或图表顶部的特征

python - 为什么我的函数会在函数范围之外更改其参数?

c# - 禁用按钮时如何避免颜色变化?

colors - Raspberry Pi + neopixel : If brightness of RGB LEDs are reduced, 这是否意味着某些颜色无法渲染?

python - 如何从一组点绘制最大的多边形