21

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

1 Answer 1

22

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

Sign up to request clarification or add additional context in comments.

1 Comment

Something like import matplotlib as mpl and mpl.rcParams['figure.dpi'] = 300 will work for setting the default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.