Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Matplotlib Histogram Color

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.

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 enter image description here

like image 800
user58925 Avatar asked Feb 11 '17 05:02

user58925


People also ask

How do you determine the color of a histogram?

The formation of a color histogram is rather simple. From the definition above, we can simply count the number of pixels for each 256 scales in each of the 3 RGB channel, and plot them on 3 individual bar graphs. In general, a color histogram is based on a certain color space, such as RGB or HSV.

How do I make different color bars Python?

You can change the color of bars in a barplot using color argument. RGB is a way of making colors. You have to to provide an amount of red, green, blue, and the transparency value to the color argument and it returns a color.


1 Answers

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")
like image 82
ImportanceOfBeingErnest Avatar answered Sep 20 '22 09:09

ImportanceOfBeingErnest