Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase image size of pandas.DataFrame.plot

How can I modify the size of the output image of the function pandas.DataFrame.plot?

I tried:

plt.figure (figsize=(10,5))

and

%matplotlib notebook

but none of them work.

like image 642
mommomonthewind Avatar asked Jul 04 '18 13:07

mommomonthewind


People also ask

How do I increase a figure size in Matplotlib?

figure(figsize=(1,1)) would create an inch-by-inch image, which would be 80-by-80 pixels unless you also give a different dpi argument. If you've already got the figure created, say it's 'figure 1' (that's the default one when you're using pyplot), you can use figure(num=1, figsize=(8, 6), ...) to change it's size etc.

How do I enlarge pandas Dataframe?

Pandas DataFrame - expanding() functionThe expanding() function is used to provide expanding transformations. Minimum number of observations in window required to have a value (otherwise result is NA). Set the labels at the center of the window.


1 Answers

Try the figsize parameter in df.plot(figsize=(width,height)):

df = pd.DataFrame({"a":[1,2],"b":[1,2]}) df.plot(figsize=(3,3)); 

Enter image description here

df = pd.DataFrame({"a":[1,2],"b":[1,2]}) df.plot(figsize=(5,3)); 

Enter image description here

The size in figsize=(5,3) is given in inches per (width, height).

An alternative way is to set desired figsize at the top of the Jupyter Notebook, prior to plotting:

plt.rcParams["figure.figsize"] = (10, 5) 

This change will affect all the plots, following this statement.


As per explanation why it doesn't work for the OP:

plt.figure(figsize=(10,5)) doesn't work because df.plot() creates its own matplotlib.axes.Axes object, the size of which cannot be changed after the object has been created. For details please see the source code. Though, one can change default figsize prior to creation, by changing default figsize with plt.rcParams["figure.figsize"] = (width, height)

like image 175
Sergey Bushmanov Avatar answered Oct 07 '22 02:10

Sergey Bushmanov