Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale plot size of Matplotlib Plots in Jupyter Notebooks

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
like image 524
Timon Avatar asked Jun 23 '17 14:06

Timon


People also ask

How do I change the size of a plot in Jupyter notebook?

Next, to increase the size of the plot in the jupyter notebook use plt. rcParams[“figure. figsize”] method and set width and height of the plot.


1 Answers

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

like image 154
ImportanceOfBeingErnest Avatar answered Sep 17 '22 22:09

ImportanceOfBeingErnest