If you want to show black bar edgecolors for all histograms in the current runtime (e.g. current Jupyter kernel), you can do so by using rcParams
. Since histograms are actually bar charts under the hood (calls .bar
) which in turn adds Rectangle patches to the Axes, the key to set to True is 'patch.force_edgecolor'
.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['patch.force_edgecolor'] = True # show edgecolor
gaussian_numbers = np.random.default_rng(0).normal(0, 1, 1000)
plt.hist(gaussian_numbers);
On a related note, even though edgecolor
, linewidth
, alpha
etc. are not listed among .hist
parameters, they can be found among the Rectangle properties (because these parameters change how the bars are drawn). This is useful to know especially if you are using another library that uses matplotlib to plot histograms such as pandas, seaborn etc. Then pass the patch parameters to change facecolor, alpha, edgecolor etc.
s = pd.Series(gaussian_numbers)
s.plot.hist(ec='k', alpha=0.5, fc='r') # light-red bars with black outline
In the opposite direction, if you don't want to show the bar outlines, pass ec='none'
:
plt.hist(gaussian_numbers, ec='none');
This will not draw edgecolors no matter what the rcParams settings are.
edgecolor = "k"
indeed brings the lines back in matplotlib 2.0. – Locke