Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么条形图的线条颜色是黑色?_Python_Colors_Matplotlib_Bar Chart - Fatal编程技术网

Python 为什么条形图的线条颜色是黑色?

Python 为什么条形图的线条颜色是黑色?,python,colors,matplotlib,bar-chart,Python,Colors,Matplotlib,Bar Chart,我正在使用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()

我正在使用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时程序的图片。

此时列表的长度为99。

该文件可在以下位置获得:

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


谢谢。

你们酒吧的边框是黑色的。有可能,当你有这么多的酒吧,他们变得非常狭窄和边界挤在一起,所以你只看到边界,而不是彩色的内部。试着放大图形,看看颜色是否存在。您还可以将
edgecolor='none'
参数传递给
bar
,以删除边框。

您的边框变得非常密集,只有边框可见。因为它们是黑色的,所以你看到的主要是黑色。有两种可能的解决方法:

a) 增加你的酒吧宽度

b) 删除你的酒吧的边界