matplotlib histogram: how to display the count over the bar?

New in matplotlib 3.4.0 There is a new plt.bar_label method to automatically label bar containers. plt.hist returns the bar container(s) as the third output: data = np.random.default_rng(123).rayleigh(1, 70) counts, edges, bars = plt.hist(data) # ^ plt.bar_label(bars) If you have a grouped or stacked histogram, bars will contain multiple containers (one per group), so iterate: fig, … Read more

How to add edge color to a histogram

As part of the update to matplotlib 2.0 the edges on bar plots are turned off by default. However, this behavior can be globally changed with rcParams. plt.rcParams[“patch.force_edgecolor”] = True Alternatively, set the edgecolor / ec parameter in the plot call, and potentially increase the linewidth / lw parameter. Tested in python 3.11.4, pandas 2.0.3, … Read more

Plot two histograms on single chart

Here you have a working example: import random import numpy from matplotlib import pyplot x = [random.gauss(3,1) for _ in range(400)] y = [random.gauss(4,2) for _ in range(400)] bins = numpy.linspace(-10, 10, 100) pyplot.hist(x, bins, alpha=0.5, label=”x”) pyplot.hist(y, bins, alpha=0.5, label=”y”) pyplot.legend(loc=”upper right”) pyplot.show()

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)