Home > Backend Development > Python Tutorial > How to Adjust Figure Dimensions in Matplotlib?

How to Adjust Figure Dimensions in Matplotlib?

Mary-Kate Olsen
Release: 2024-12-16 01:35:09
Original
331 people have browsed it

How to Adjust Figure Dimensions in Matplotlib?

Adjusting Figure Dimensions in Matplotlib

How can you alter the dimensions of figures created using Matplotlib?

Answer:

The figure() method provides control over the size of the generated figure. Its syntax is:

from matplotlib.pyplot import figure

figure(figsize=(width, height), dpi=resolution)
Copy after login
  • figsize: A tuple representing the width and height of the figure in inches. For example, figure(figsize=(8, 6)) creates an 8-inch-wide and 6-inch-high figure.
  • dpi: Optional argument specifying the resolution in dots per inch (DPI). A higher DPI results in a sharper image.

By default, Matplotlib uses a DPI of 80. Therefore, an inch-by-inch figure (figure(figsize=(1,1))) would translate to an 80-by-80 pixel image. Providing a different DPI argument, such as figure(figsize=(1,1), dpi=100), would produce a 100-by-100 pixel image.

The above is the detailed content of How to Adjust Figure Dimensions in Matplotlib?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template