- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Plotting a histogram from pre-counted data in Matplotlib
To plot a histogram from pre-counted data in matplotlib, we can take the following steps −
Create a list of numbers.
Make a pre-counted list with the help of input data.
Plot a histogram with data, color=red, and label=data, using hist() method.
Plot another histogram with counted data, color=default, and label=counted_data, using hist() method.
To place the legend, use legend() method.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = [1, 2, 2, 3, 4, 5, 5, 5, 5, 6, 10] counted_data = {1: 1, 2: 2, 3: 1, 4: 1, 5: 4, 6: 1, 10: 1} hh = plt.hist(data, bins=len(data), rwidth=.95, color='red', label="data") hh1 = plt.hist(counted_data.keys(), weights=counted_data.values(), bins=range(10), rwidth=.95, label="counted_data") plt.legend() plt.show()
Output
- Related Articles
- Plotting a transparent histogram with non-transparent edge in Matplotlib
- How to plot a line graph from histogram data in Matplotlib?
- How to make a histogram from a list of data in Matplotlib?
- Plotting a 3D surface from a list of tuples in matplotlib?
- Plot a histogram with colors taken from colormap in Matplotlib
- Plotting error bars from a dataframe using Seaborn FacetGrid (Matplotlib)
- How to plot a histogram using Matplotlib in Python with a list of data?
- Matplotlib – Make a Frequency histogram from a list with tuple elements in Python
- Setting a relative frequency in a Matplotlib histogram
- Plotting power spectral density in Matplotlib
- Plotting profile histograms in Python Matplotlib
- How to plot a 2D histogram in Matplotlib?
- Annotate data points while plotting from Pandas DataFrame
- Vertical Histogram in Python and Matplotlib
- Plotting a cumulative graph of Python datetimes in Matplotlib

Advertisements