Reputation: 1633
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.
plt.hist(data, color = "skyblue")
Below is how the histogram looks. As you can see, even though I specified the color to be "Skyblue, the histogram on the right is nearly black.
Upvotes: 23
Views: 175524
Reputation: 23361
This particular problem (where edgecolor doesn't match the bar color) doesn't exist anymore (at least as of matplotlib 3.0) because unless edgecolor matches the fill color by default.
Anyway, a faster way to plot a histogram (where edgecolor doesn't matter) is to plot the outline and fill it.
data = (np.random.randn(10000)-2.5)/4
plt.hist(data, bins=50, histtype='step', fill=True, color='skyblue');
Another way is to precompute the histogram using np.histogram
, plot the outline using plt.stairs()
and fill it.
plt.stairs(*np.histogram(data, 50), fill=True, color='skyblue')
Both options are much faster than a bare plt.hist()
call especially if the number of bins is high.
Upvotes: 0
Reputation: 339610
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")
Upvotes: 34