Python Matplotlib 直方图颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42172440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python Matplotlib Histogram Color
提问by user58925
I hope you are well.
我希望你一切都好。
I am plotting a histogram using Matplotlib. I would like the color of the histogram to be "sky blue". But the data overlaps, and produces a histogram which is nearly black in color.
我正在使用 Matplotlib 绘制直方图。我希望直方图的颜色为“天蓝色”。但数据重叠,并产生一个颜色接近黑色的直方图。
Thanks for helping
谢谢你的帮助
plt.hist(data, color = "skyblue")
Below is how the histogram looks. As you can see, though I've specified the color as "Skyblue, the histogram on the right is nearly black
回答by ImportanceOfBeingErnest
The reason for the histogram to look black is that the bars' surrounding lines (which are black) take most of the space.
直方图看起来是黑色的原因是条形周围的线条(黑色)占据了大部分空间。
Options would be to get rid of the edges by setting the linewidth to zero:
选项是通过将线宽设置为零来消除边缘:
plt.hist(data, color = "skyblue", lw=0)
and/or to set the edgecolor to the same color as the bars itself
和/或将边缘颜色设置为与条形本身相同的颜色
plt.hist(data, color = "skyblue", ec="skyblue")