Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change DPI of my Pandas Dataframe Plot?

I'm trying to change the DPI of my Pandas Dataframe Plot.

I've tried this code but doesn't give me the right result (no DPI change):

fig = plt.figure(dpi=140)

my_data.sample(250).plot(kind="scatter", x="X data", y="Y")

plt.plot(x_data, y_hat, "r", lw=3, alpha=0.6)

plt.show()

Thanks

like image 834
JulienRioux Avatar asked Jan 12 '18 13:01

JulienRioux


People also ask

How to change the DPI of a pandas Dataframe plot in Matplotlib?

How to change the DPI of a Pandas Dataframe Plot in Matplotlib? To change the DPI of a Pandas DataFrame plot, we can use rcParams to set the dot per inch. Set the figure size and adjust the padding between and around the subplots.

How to plot a Dataframe to an existing figure's axes?

Instead a new figure is created. To plot a dataframe to an existing figure's axes, you may use the ax argument. Alternatively you may set the dpi of any figure being created using rcParams.

What are the different types of plot in pandas Dataframe?

pandas.DataFrame.plot ¶ 1 ‘line’ : line plot (default) 2 ‘bar’ : vertical bar plot 3 ‘barh’ : horizontal bar plot 4 ‘hist’ : histogram 5 ‘box’ : boxplot 6 ‘kde’ : Kernel Density Estimation plot 7 ‘density’ : same as ‘kde’ 8 ‘area’ : area plot 9 ‘pie’ : pie plot 10 ‘scatter’ : scatter plot 11 ‘hexbin’ : hexbin plot. More ...

What is set_dpi () Method in Matplotlib?

The set_dpi () method figure module of matplotlib library is used to set the resolution of the figure in dots-per-inch. Syntax: set_dpi (self, val) Parameters: This method accept the following parameters that are discussed below: val : This parameter is the float value.


1 Answers

The dataframe is not plotted to the figure of which you changed the dpi. Instead a new figure is created. To plot a dataframe to an existing figure's axes, you may use the ax argument.

fig = plt.figure(dpi=140)
df.plot(..., ax = plt.gca())

Alternatively you may set the dpi of any figure being created using rcParams.

plt.rcParams["figure.dpi"] = 140
df.plot(...)
like image 134
ImportanceOfBeingErnest Avatar answered Sep 28 '22 17:09

ImportanceOfBeingErnest