DEV Community

Kaira Kelvin.
Kaira Kelvin.

Posted on • Edited on

How to Change Plot Size in Matplotlib.

The default parameters (in inches) for matplotlib plots are (6.4)wide and (4.8) high, instance

import matplotlib.pyplot as plt
      X =[ 2,2,5,5]
      y =[10,5,6,8]
      plt.plot(x,y)
      plt.show()
Enter fullscreen mode Exit fullscreen mode

We change the size of the plot above using the figsize() attribute of the figure()function - the figsize attribute takes in two parameters one for width and the other for height.
** syntax**

figure(figsize=WIDTH_SIZE,HEIGHT_SIZE)
    plt.figure(figsize=(10,6))
Enter fullscreen mode Exit fullscreen mode

Still, u can use set_figwidth() method to change the width of a plot.
syntax

 plt.figure().set_figwidth()
  plt.plot(x,Y)
  plt.show()
Enter fullscreen mode Exit fullscreen mode

For setting the height size here the code:
syntax

 Set_figheight()
         plt.figure().set_figheight(3)
         plt.plot(x,y)
         plt.show()
Enter fullscreen mode Exit fullscreen mode

How to Change Default Plot Size in Matplotlib with rcParams
This is useful when you want all your plots to follow a particular size. This means you don't have to change the size of every plot you create.
rcParams stands for (runtime configuration parameters )it stores the default settings for various plotting parameters.These parameters control the appearance of plots, such as , the size of figures, line styles, font sizes, color schemes, and many other aspects of the plot. By modifying the values in rcParams, you can customize the default settings for your plots.

Top comments (0)