How to Change the Size of Figures in Matplotlib?
Last Updated :
15 Mar, 2025
Matplotlib provides a default figure size of 6.4 inches in width and 4.8 inches in height. While this is suitable for basic graphs, various situations may require resizing figures for better visualization, presentation or publication. This article explores multiple methods to adjust the figure size in Matplotlib.
Why change the figure size?
Changing the size of a figure is important for several reasons:
- Enhances readability when dealing with large datasets.
- Improves visual appeal in presentations and reports.
- Ensures proper layout in print or digital formats.
- Allows better customization for multi-panel plots.
Changing Figure Size using figsize Parameter
To change the size of a figure in matplotlib, we can use the figsize parameter of the plt.figure() function. The figsize attribute allows you to specify the width and height in inches. In the example given below we create a Matplotlib figure sized 5 inches wide by 2 inches tall to plot the quadratic equation [Tex]Y=X^2[/Tex]. The graph displays the resulting curve of this equation.
Python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-5, 5, 100)
y = x**2
plt.figure(figsize=(5, 2))
plt.plot(x, y)
plt.title('Plot of y = x^2')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
Output:

setting figsize with dimensions 5 inches in width and 2 inches in height
Explanation: numpy generates 100 evenly spaced x-values using np.linspace(-5, 5, 100), and y-values are computed as [Tex]y=x^2[/Tex] . The figure size is set with plt.figure(figsize=(5, 2)), creating a 5-inch wide and 2-inch high plot for a compact layout. The function is plotted using plt.plot(x, y) and titles and labels are added with plt.title(), plt.xlabel() and plt.ylabel().
Setting Width of the Figure with set_figwidth()
set_figwidth() method allows you to adjust the width of a plot. By passing the desired width as a parameter, you can change the plot’s width without affecting its default or preset height. Example:
Python
import matplotlib.pyplot as plt
x = [1, 3, 5, 7, 9]
y = [5, 7, 2, 8, 4]
plt.figure().set_figwidth(20)
plt.plot(x, y)
plt.show()
Output:

using set_figwidth() function
Explanation: The figure width is set to 20 inches using plt.figure().set_figwidth(20), making the plot significantly wider for better readability. The function plt.plot(x, y) draws the line connecting the data points.
Setting Height of Figure with set_figheight()
You can use the set_figheight() method to change the height of a plot. This method will not change the default or preset value of the plot’s width. Example:
Python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [12, 5, 18, 7, 9]
plt.figure().set_figheight(5)
plt.plot(x, y)
plt.show()
Output:

using set_height() function
Explanation: This code plots a line graph using Matplotlib while adjusting the figure height with set_figheight(5). The figure height is set to 5 inches, keeping the default width unchanged.
Changing the Size of Figure using set_size_inches()
For greater flexibility, set_size_inches() allows you to specify both dimensions explicitly. Example: Setting custom width and height
Python
import matplotlib.pyplot as plt
fig = plt.figure()
fig.set_size_inches(5, 5)
x = [1, 2, 3, 4, 5]
y = [x*2 for x in x]
plt.plot(x, y)
plt.show()
Output:

Explanation: A figure is created with plt.figure(), set to 5×5 inches for a square aspect ratio. The x-values [1, 2, 3, 4, 5] are plotted against y-values, computed as x × 2.
Similar Reads
How to change the size of figures drawn with matplotlib?
Matplotlib provides a default figure size of 6.4 inches in width and 4.8 inches in height. While this is suitable for basic graphs, various situations may require resizing figures for better visualization, presentation or publication. This article explores multiple methods to adjust the figure size
3 min read
How to change the font size of the Title in a Matplotlib figure ?
In this article, we are going to discuss how to change the font size of the title in a figure using matplotlib module in Python. As we use matplotlib.pyplot.title() method to assign a title to a plot, so in order to change the font size, we are going to use the font size argument of the pyplot.title
2 min read
How to Change the Figure Size with Subplots in Matplotlib
Matplotlib is a powerful plotting library in Python that allows users to create a wide variety of static, animated, and interactive plots. One common requirement when creating plots is to adjust the figure size, especially when dealing with subplots. This article will guide you through the process o
4 min read
How to Change the Font Size of Colorbars in Matplotlib
Matplotlib is a powerful and widely used library in Python for data visualization. It offers a variety of plotting functions to create complex graphs and charts. One common visualization is a heatmap, which often includes a color bar to indicate the scale of values represented by colors. Adjusting t
4 min read
How to change the size of axis labels in Matplotlib?
Matplotlib is a Python library that helps in visualizing and customizing various plots. One of the customization you can do is to change the size of the axis labels to make reading easier. In this guide, weâll look how to adjust font size of axis labels using Matplotlib. Letâs start with a basic plo
2 min read
How to change figure size in Plotly in Python
In this article, we will discuss how we can change the figure size in Plotly in Python. Let's firstly take about Plotly in Python. Plotly  Python library provides us with an interactive open-source Plotly library that can support over 40 unique chart types that cover a wide list of statistical, fin
4 min read
How to Change Legend Font Size in Matplotlib?
Matplotlib is a library for creating interactive Data visualizations in Python. The functions in Matplotlib make it work like MATLAB software. The legend method in Matplotlib describes the elements in the plot. In this article, we are going to Change Legend Font Size in Matplotlib. Using pyplot.lege
3 min read
How to change Matplotlib color bar size in Python?
Colorbar is a separate axis that provides a current colormap indicating mapping of data-points into colors. In this article, We are going to change Matplotlib color bar size in Python. There are several ways with which you can resize your color-bar or adjust its position. Let's see it one by one. Me
2 min read
Change the x or y interval of a Matplotlib figure
It is quite easy to change the x or y range using matplotlib.pyplot.xlim() and matplotlib.pyplot.ylim() from the Matplotlib is a library in Python. This function in pyplot module of matplotlib library is used to get or set the x-limits/ y-limits of the current axes and returns the tuple of the new x
1 min read
How to Change Fonts in matplotlib?
Prerequisites: Matplotlib In this article, we will see how can we can change the font family of our graph using matplotlib. A variety of fonts are in fact supported by matplotlib, alone has to do in order to implement is pass the name as value to fontname parameter. Approach: Import required library
2 min read