
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Save figure as file from iPython notebook using Matplotlib
To save a figure as a file from iPython, we can take the following steps−
- Create a new figure or activate an existing figure.
- Add an axes to the figure using add_axes() method.
- Plot the given list.
- Save the plot using savefig() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_axes([1, 1, 1, 1]) plt.plot([1, 2]) plt.savefig('test.png', bbox_inches='tight')
Output
When we execute the code, it will save the following plot as "test.png".
- Related Articles
- How to set the matplotlib figure default size in ipython notebook?
- Automatically run %matplotlib inline in IPython Notebook
- Matplotlib animation not working in IPython Notebook?
- How do I show the same Matplotlib figure several times in a single IPython notebook?
- How to hide in IPython notebook?
- Best way to display Seaborn/Matplotlib plots with a dark iPython Notebook profile
- Exporting an svg file from a Matplotlib figure
- Plot width settings in ipython notebook\n\n
- How to save a matrix as CSV file using R?
- Displaying rotatable 3D plots in IPython or Jupyter Notebook
- How to extract text from a web page using Selenium and save it as a text file?
- How can I dynamically update my Matplotlib figure as the data file changes?
- Plot data from a .txt file using matplotlib
- How to dynamically update a plot in a loop in Ipython notebook?
- How to change the default path for "save the figure" in Matplotlib?

Advertisements