How to save a Matplotlib figure as a certain size in Python

Saving a Matplotlib figure as a certain size saves it with particular dimensions and dots per inch (DPI). For example, setting the dimensions of the figure to 8-by-6 inches and its DPI to 100 saves it with an 800×600 resolution.

Solution for How to save a Matplotlib figure as a certain size in Python : You can use matplotlib.figure.Figure.set_size_inches() and matplotlib.pyplot.savefig() to save a figure as a certain size Call matplotlib.pyplot.gcf() to get the current figure. Use matplotlib.figure.Figure.set_size_inches(width, height) with the previous result to set the dimensions of the figure to a certain width and height, in inches. Call matplotlib.pyplot.savefig(filename, dpi=100) with dpi set to the desired pixels per inch to save the figure as filename.


how-to-save-a-matplotlib-figure-as-a-certain-size-in-python