JulienRioux
JulienRioux

Reputation: 3092

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

Upvotes: 20

Views: 16512

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

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

Related Questions