- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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?
63 Lectures 6 hours
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.
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()
It will save the following plot as 'hist.png' in the project directory.
- How to save a plot in Seaborn with Python (Matplotlib)?
- How to plot a 2D histogram in Matplotlib?
- 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?
- How to plot a histogram using Matplotlib in Python with a list of data?
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- How to normalize a histogram in Python?
- How to plot a line graph from histogram data in Matplotlib?
- How to save the plot to a numpy array in RGB format?
- How to make a log histogram in Python?
- How to save a Librosa spectrogram plot as a specific sized image?
- How to save a plot as SVG created with ggplot2 in R?
- How to have logarithmic bins in a Python histogram?