🌐
Matplotlib
matplotlib.org › stable › api › _as_gen › matplotlib.pyplot.hist.html
matplotlib.pyplot.hist — Matplotlib 3.11.2 documentation
counts, bins = np.histogram(x) plt.stairs(counts, bins) Alternatively, plot pre-computed bins and counts using hist() by treating each bin as a single point with a weight equal to its count: plt.hist(bins[:-1], bins, weights=counts) The data input x can be a singular array, a list of datasets of potentially different lengths ([x0, x1, ...]), or a 2D ndarray in which each column is a dataset.
🌐
GeeksforGeeks
geeksforgeeks.org › python › matplotlib-pyplot-hist-in-python
Matplotlib.pyplot.hist() in Python - GeeksforGeeks
March 18, 2026 - Lets consider the data values and visualise histogram with help of an example: ... import matplotlib.pyplot as plt data = [32, 96, 45, 67, 76, 28, 79, 62, 43, 81, 70,61, 95, 44, 60, 69, 71, 23 ,69, 54, 76, 67,82, 97, 26, 34, 18, 16, 59, 88, 29, 30, 66,23, 65, 72, 20, 78, 49, 73, 62, 87, 37, 68,81, 80, 77, 92, 81, 52, 43, 68, 71, 86] plt.hist(data) plt.show()
People also ask

Can plt.hist() handle pandas Series and DataFrame columns directly?
Yes. plt.hist() accepts any array-like input, including pandas Series. You can pass df['column_name'] directly. For plotting from a DataFrame using pandas' built-in method, use df['column_name'].plot.hist(bins=30).
🌐
docs.kanaries.net
docs.kanaries.net › topics › Matplotlib › matplotlib-histogram
Matplotlib Histogram: The Complete Guide to plt.hist() in Python ...
What is the difference between density=True and cumulative=True in plt.hist()?
density=True normalizes the histogram so the total area under all bars equals 1, converting the y-axis to probability density. cumulative=True makes each bar represent the sum of all previous bars plus itself. You can combine both to produce a cumulative distribution function.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Matplotlib › matplotlib-histogram
Matplotlib Histogram: The Complete Guide to plt.hist() in Python ...
How do I overlay two histograms in matplotlib?
Call plt.hist() twice with the same bins value and set alpha to a value less than 1 so both distributions remain visible. Add label to each call and finish with plt.legend(). Using histtype='step' avoids the need for transparency since it draws only outlines.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Matplotlib › matplotlib-histogram
Matplotlib Histogram: The Complete Guide to plt.hist() in Python ...
🌐
Matplotlib
matplotlib.org › stable › gallery › statistics › hist.html
Histograms — Matplotlib 3.11.2 documentation
To plot a 2D histogram, one only needs two vectors of the same length, corresponding to each axis of the histogram. fig, ax = plt.subplots(tight_layout=True) hist = ax.hist2d(dist1, dist2)
🌐
Analytics Vidhya
analyticsvidhya.com › home › matplotlib.pyplot.hist() in python: guide to plotting histograms
Matplotlib.pyplot.hist() in Python: Guide to Plotting Histograms - Analytics Vidhya
February 8, 2024 - To create a histogram using matplotlib.pyplot.hist(), we need to provide the data we want to plot and specify the number of bins. The function then calculates the frequency of values falling within each bin and plots a bar for each bin, representing ...
🌐
W3Schools
w3schools.com › python › matplotlib_histograms.asp
Matplotlib Histograms
import matplotlib.pyplot as plt import numpy as np x = np.random.normal(170, 10, 250) plt.hist(x) plt.show() ... Coding fundamentals as bite-sized lessons and challenges. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Kanaries
docs.kanaries.net › topics › Matplotlib › matplotlib-histogram
Matplotlib Histogram: The Complete Guide to plt.hist() in Python – Kanaries
February 9, 2026 - The simplest histogram requires only one argument: the data array. import matplotlib.pyplot as plt import numpy as np # Generate 1000 normally distributed values np.random.seed(42) data = np.random.normal(loc=50, scale=15, size=1000) plt.hist(data) plt.title('Basic Histogram') plt.xlabel('Value') plt.ylabel('Frequency') plt.show()
🌐
StrataScratch
stratascratch.com › blog › how-to-create-a-matplotlib-histogram
How to Create a Matplotlib Histogram? - StrataScratch
March 10, 2025 - For now, you should remember that transparency is changed by passing values between 0 (the highest transparency) and 1 (the lowest transparency) as an argument in the alpha parameter of hist(). In this code snapshot, the transparency is set to 0.4. import matplotlib.pyplot as plt data = ( [-2.5, -2.3, -2.1] * 5 + [-1.9, -1.8, -1.6, -1.5, -1.4] * 10 + [-1.3, -1.2, -1.1, -1.0, -0.9] * 15 + [-0.8, -0.7, -0.6, -0.5, -0.4] * 20 + [-0.3, -0.2, -0.1, 0.0, 0.1, 0.2] * 25 + [0.3, 0.4, 0.5, 0.6, 0.7] * 20 + [0.8, 0.9, 1.0, 1.1, 1.2] * 15 + [1.3, 1.4, 1.5, 1.6, 1.8] * 10 + [1.9, 2.0, 2.1, 2.3, 2.5] * 5 ) plt.figure(figsize=(8, 4)) plt.hist(data, bins=15, alpha=0.4, edgecolor='black', color='lightsalmon') plt.grid(True) plt.show()
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › data visualization › plotting-histogram-in-python-using-matplotlib
Plotting Histogram in Python using Matplotlib - GeeksforGeeks
A basic histogram groups numerical data into bins and displays the frequency of values in each interval. It provides a quick overview of how the data is distributed. ... import matplotlib.pyplot as plt import numpy as np data = np.random.randn(1000) ...
Published: July 16, 2026
🌐
Matplotlib
matplotlib.org › 3.1.1 › api › _as_gen › matplotlib.pyplot.hist.html
matplotlib.pyplot.hist — Matplotlib 3.1.2 documentation
matplotlib.pyplot.hist(x, bins=None, range=None, density=None, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False, color=None, label=None, stacked=False, normed=None, *, data=None, **kwargs)[source]¶
Top answer
1 of 7
301

If you want a histogram, you don't need to attach any 'names' to x-values because:

  • on x-axis you will have data bins
  • on y-axis counts (by default) or frequencies (density=True)
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

np.random.seed(42)
x = np.random.normal(size=1000)

plt.hist(x, density=True, bins=30)  # density=False would make counts
plt.ylabel('Probability')
plt.xlabel('Data');

Note, the number of bins=30 was chosen arbitrarily, and there is Freedman–Diaconis rule to be more scientific in choosing the "right" bin width:

, where IQR is Interquartile range and n is total number of datapoints to plot

So, according to this rule one may calculate number of bins as:

q25, q75 = np.percentile(x, [25, 75])
bin_width = 2 * (q75 - q25) * len(x) ** (-1/3)
bins = round((x.max() - x.min()) / bin_width)
print("Freedman–Diaconis number of bins:", bins)
plt.hist(x, bins=bins);

Freedman–Diaconis number of bins: 82

And finally you can make your histogram a bit fancier with PDF line, titles, and legend:

import scipy.stats as st

plt.hist(x, density=True, bins=82, label="Data")
mn, mx = plt.xlim()
plt.xlim(mn, mx)
kde_xs = np.linspace(mn, mx, 300)
kde = st.gaussian_kde(x)
plt.plot(kde_xs, kde.pdf(kde_xs), label="PDF")
plt.legend(loc="upper left")
plt.ylabel("Probability")
plt.xlabel("Data")
plt.title("Histogram");

If you're willing to explore other opportunities, there is a shortcut with seaborn:

# !pip install seaborn
import seaborn as sns
sns.displot(x, bins=82, kde=True);

Now back to the OP.

If you have limited number of data points, a bar plot would make more sense to represent your data. Then you may attach labels to x-axis:

x = np.arange(3)
plt.bar(x, height=[1,2,3])
plt.xticks(x, ['a','b','c']);

2 of 7
27

If you haven't installed matplotlib yet just try the command.

> pip install matplotlib

Library import

import matplotlib.pyplot as plot

The histogram data:

plot.hist(weightList,density=1, bins=20) 
plot.axis([50, 110, 0, 0.06]) 
#axis([xmin,xmax,ymin,ymax])
plot.xlabel('Weight')
plot.ylabel('Probability')

Display histogram

plot.show()

And the output is like :

🌐
CodeSignal
codesignal.com › learn › courses › introduction-to-basic-plots-with-matplotlib › lessons › creating-histograms-with-matplotlib
Creating Histograms with Matplotlib | CodeSignal Learn
The plt.hist() function automatically divides the penguins['bill_depth_mm'] data into bins and calculates the count of data points within each bin.
🌐
Python Graph Gallery
python-graph-gallery.com › basic-histogram-in-matplotlib
Basic histogram in Matplotlib
You can return your histogram horizontallys by adding orientation='horizontal' to the hist() function. fig, ax = plt.subplots(figsize=(5,5)) ax.hist(hours, orientation='horizontal', bins=5) plt.show()
🌐
Matplotlib
matplotlib.org › 3.1.0 › api › _as_gen › matplotlib.pyplot.hist.html
matplotlib.pyplot.hist — Matplotlib 3.1.0 documentation
matplotlib.pyplot.hist(x, bins=None, range=None, density=None, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False, color=None, label=None, stacked=False, normed=None, *, data=None, **kwargs)[source]¶
🌐
Matplotlib
matplotlib.org › 2.1.0 › api › _as_gen › matplotlib.pyplot.hist.html
matplotlib.pyplot.hist — Matplotlib 2.1.0 documentation
matplotlib.pyplot.hist(x, bins=None, range=None, density=None, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False, color=None, label=None, stacked=False, normed=None, hold=None, data=None, **kwargs)¶
🌐
Educative
educative.io › answers › what-is-matplotlibpyplothist-in-python
What is matplotlib.pyplot.hist() in Python?
The function returns a tuple that contains the frequencies of the histogram bins, the edges of the bins, and the respective patches that create the histogram.
🌐
Canard Analytics
canardanalytics.com › blog › histogram-matplotlib
Plotting Histograms with Matplotlib | Canard Analytics
August 10, 2022 - There are a few imports we need to make in order to complete this tutorial. In addition to matplotlib.pyplot which houses the hist function we will also be making use of the numpy, pandas, and statistics packages. import matplotlib.pyplot as plt import numpy as np import pandas as pd import statistics
🌐
TutorialsPoint
tutorialspoint.com › matplotlib › matplotlib_histogram.htm
Matplotlib - Histogram
In the following example, we are creating a vertical histogram by setting the "orientation" parameter to "vertical" within the hist() function − · import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 2, 3, 1, 2, 3, 4, 1, 3, 4, 5] plt.hist(x, orientation="vertical") plt.show()
🌐
Pythonforall
pythonforall.com › modules › matplotlib › plthist
Histograms in Matplotlib | PythonForAll
February 9, 2026 - # Data data1 = [22, 87, 5, 42, 88, 30, 56] data2 = [32, 57, 15, 72, 48, 50, 66] # Define bin edges bins = [0, 20, 40, 60, 80, 100] # Create side-by-side histograms plt.hist([data1, data2], bins=bins, label=["Dataset 1", "Dataset 2"], color=['blue', 'green'], edgecolor='black') # Add title, labels, and legend plt.title("Side-by-Side Histograms") plt.xlabel("Value Range") plt.ylabel("Frequency") plt.legend() # Display the plot plt.show()
🌐
DataCamp
datacamp.com › tutorial › histograms-matplotlib
Histograms in Matplotlib | DataCamp
June 17, 2019 - Plotting histogram using matplotlib is a piece of cake. All you have to do is use plt.hist() function of matplotlib and pass in the data along with the number of bins and a few optional parameters.