19

Is there a possibility to scale the plot size of matplotlib plots in jupyter notebooks? You could increase the plot size by changing the default values of figure.figsize, but this does not affect parameters like fontsize, linewidth, markersize etc. What I need is a plot where all the parameters are scaled accordingly.

P.S.: To display plots in jupyter notebooks I use %matplotlib inline, see screenshot below.

Image

Edit

For completeness, here is a code snippet doing exactly what I needed:

def scale_plot_size(factor=1.5):
    import matplotlib as mpl
    default_dpi = mpl.rcParamsDefault['figure.dpi']
    mpl.rcParams['figure.dpi'] = default_dpi*factor
Timon
  • 343
  • 1
  • 3
  • 6

1 Answers1

21

You don't want to change the figure size. You want to change the dpi (dots per inch).
Also see Relationship between dpi and figure size.

import matplotlib.pyplot as plt
%matplotlib inline

def plot(dpi):
    fig, ax=plt.subplots(dpi=dpi)
    ax.plot([2,4,1,5], label="Label")
    ax.legend()

for i in range(1,4):
    plot(i*72)

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    Something like `import matplotlib as mpl` and `mpl.rcParams['figure.dpi'] = 300` will work for setting the default. – Dave X Mar 08 '21 at 14:35