- 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
How to save a histogram plot in Python?
To save a histogram plot in Python, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create data points "k" for the histogram.
- Plot the histogram using hist() method.
- To save the histogram, use plt.savefig('image_name').
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Data points for the histogram k = [1, 3, 2, 5, 4, 7, 5, 1, 0, 4, 1] # Plot the histogram plt.hist(k) # Save the histogram plt.savefig('hist.png') # Display the plot plt.show()
Output
It will save the following plot as 'hist.png' in the project directory.
- Related Articles
- How to save a plot in Seaborn with Python (Matplotlib)?
- How to plot a 2D histogram in Matplotlib?
- How to plot a histogram using Matplotlib in Python with a list of data?
- How to plot hexbin histogram in Matplotlib?
- How to center labels in a Matplotlib histogram plot?
- How to save a plot in pdf in R?
- How to plot collections.Counter histogram using Matplotlib?
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- How to plot a line graph from histogram data in Matplotlib?
- How to normalize a histogram in Python?
- OpenCV Python – How to compute and plot the histogram of a region of an image?
- How to save the plot to a numpy array in RGB format?
- How to make a log histogram in Python?
- How to save a plot as SVG created with ggplot2 in R?
- How to have logarithmic bins in a Python histogram?

Advertisements