<jupyter_start><jupyter_text>Producing multiple histograms side by sideThis example plots horizontal histograms of different samples alonga categorical x-axis. Additionally, the histograms are plotted tobe symmetrical about their x-position, thus making them very similarto violin plots.To make this highly specialized plot, we can't use the standard ``hist``method. Instead we use ``barh`` to draw the horizontal bars directly. Thevertical positions and lengths of the bars are computed via the``np.histogram`` function. The histograms for all the samples arecomputed using the same range (min and max values) and number of bins,so that the bins for each sample are in the same vertical positions.Selecting different bin counts and sizes can significantly affect theshape of a histogram. The Astropy docs have a great section on how toselect these parameters:http://docs.astropy.org/en/stable/visualization/histogram.html<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

np.random.seed(19680801)
number_of_bins = 20

# An example of three data sets to compare
number_of_data_points = 387
labels = ["A", "B", "C"]
data_sets = [np.random.normal(0, 1, number_of_data_points),
             np.random.normal(6, 1, number_of_data_points),
             np.random.normal(-3, 1, number_of_data_points)]

# Computed quantities to aid plotting
hist_range = (np.min(data_sets), np.max(data_sets))
binned_data_sets = [
    np.histogram(d, range=hist_range, bins=number_of_bins)[0]
    for d in data_sets
]
binned_maximums = np.max(binned_data_sets, axis=1)
x_locations = np.arange(0, sum(binned_maximums), np.max(binned_maximums))

# The bin_edges are the same for all of the histograms
bin_edges = np.linspace(hist_range[0], hist_range[1], number_of_bins + 1)
centers = 0.5 * (bin_edges + np.roll(bin_edges, 1))[:-1]
heights = np.diff(bin_edges)

# Cycle through and plot each histogram
fig, ax = plt.subplots()
for x_loc, binned_data in zip(x_locations, binned_data_sets):
    lefts = x_loc - 0.5 * binned_data
    ax.barh(centers, binned_data, height=heights, left=lefts)

ax.set_xticks(x_locations)
ax.set_xticklabels(labels)

ax.set_ylabel("Data values")
ax.set_xlabel("Data sets")

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09184587813620072, 'fraction_numerical': 0.013888888888888888, 'mean_word_length': 5.325779036827195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '367654', 'license': 'MIT', 'n_tokens_mistral': 758, 'n_tokens_neox': 708, 'n_words': 230, 'path': 'matplotlib/gallery_jupyter/statistics/multiple_histograms_side_by_side.ipynb', 'repo_name': 'kingreatwill/penter', 'size': '2232'}