- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Histogram for discrete values with Matplotlib
To plot a histogram for discrete values with matplotlib, we can use hist() method.
Steps
Set the figure size and adjust the padding between and around the subplots.
Make a list of discrete values.
Use hist() method to plot data with bins=length of data and edgecolor=black.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = [1, 4, 2, 3, 5, 9, 6, 7] plt.hist(data, bins=len(data), edgecolor='black') plt.show()
Output
- Related Articles
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- How to create histogram for discrete column in an R data frame?
- Defining a discrete colormap for imshow in Matplotlib
- Matplotlib histogram with multiple legend entries
- Getting information for bins in Matplotlib histogram function
- Display MySQL histogram with negative values?
- How to make a discrete colorbar for a scatter plot in matplotlib?
- Plot a histogram with Y-axis as percentage in Matplotlib
- Plotting a transparent histogram with non-transparent edge in Matplotlib
- Plot a histogram with colors taken from colormap in Matplotlib
- Vertical Histogram in Python and Matplotlib
- How to make a histogram with bins of equal area in Matplotlib?
- How to specify different colors for different bars in a Python matplotlib histogram?
- How to plot collections.Counter histogram using Matplotlib?
- Drawing average line in histogram in Matplotlib

Advertisements