Home >Backend Development >Python Tutorial >How Can I Change the Dimensions of a Matplotlib Figure?
How to Alter Figure Dimensions in Matplotlib
The inherent size of Matplotlib figures may not always align with desired outputs. Understanding how to adjust this dimension is crucial.
Solution:
Matplotlib's figure function offers a straightforward solution to control figure size:
from matplotlib.pyplot import figure figure(figsize=(8, 6), dpi=80)
Here, figsize represents a tuple defining the width and height of the figure in inches, while dpi indicates the image's resolution in dots per inch. By default, dpi is set to 80.
For instance, figure(figsize=(1,1)) will generate a figure measuring an inch by an inch on the screen. This corresponds to 80 by 80 pixels unless an alternative dpi is provided.
The above is the detailed content of How Can I Change the Dimensions of a Matplotlib Figure?. For more information, please follow other related articles on the PHP Chinese website!