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
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.
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.
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 ...
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.
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(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With