I'm making some plots of fitted data and saving them to files nicely with.
# Make the main plot.
ax = df.plot(x=df.x, y=['counts', 'fit', 'res'], title=save_file_name,
style=['b', 'g--', 'r'], xlim=xlim, ylim=ylim)
# Over plot some individual gaussians from my fit_gaussians dataframe.
for i, fit_gaus in fit_gaussians.iterrows():
plt.plot(df.x, gaussian(df.x, fit_gaus.h, fit_gaus.mu,
fit_gaus.sigma), 'y', linestyle='--')
# Save to file.
fig = ax.get_figure()
fig.savefig('test.ps')
This works great, but it also opens a window and plots to the screen. I know I can easily use matplotlib directly to recreate what I'm doing with df.plot, and just never call plt.show, but I feel like there should be some way create plot in a file with pandas with out also opening a window.
If you only don't want the pop ups you can do %matplotlib inline otherwise before you define ax just do:
plt.ioff()
Then whenever you want to actually show it you can do plt.show()
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