ARVIZ will not save energy or density plots

I’m having an issue saving energy plots and density plots to a folder. I’m fitting my model in a pycharm environment so the script is running command line.

The below is the code that is running after the model is fit…

inf_data = az.convert_to_inference_data(fit)
axes_post = az.plot_posterior(inf_data)
fig = axes_post.ravel()[0].figure

axes_energy = az.plot_energy(fit)


axes_density = az.plot_density(fit)


Here is the error I get:

Traceback (most recent call last):
  File "C:\Users\JORDAN.HOWELL.GITDIR\PycharmProjects\pythonProject\gooseheadquotes\Model\", line 38, in <module>
AttributeError: 'AxesSubplot' object has no attribute 'savefig'
INFO:cmdstanpy:deleting tmpfiles dir: C:\Users\JORDAN~1.GIT\AppData\Local\Temp\tmpku08_r5z

The plot posterior saves fine. So I’m not sure what the difference is.

1 Like

In first example you extract the figure object and in the second one you don’t.

Btw if some the title is cut off or something similar add bbox_inches="tight"

To save the current figure object you can use just plt.savefig

plt.savefig(filename, dpi=200, bbox_inches="tight")

To close open figures you can use

1 Like