Reputation: 3092
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
Upvotes: 20
Views: 16512
Reputation: 339072
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(...)
Upvotes: 32