Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add save to file feature #1737

Conversation

alexander-belikov
Copy link

@alexander-belikov alexander-belikov commented Jan 31, 2017

I found it useful to save figures of traces when developing graphical models, so I propose the following feature. (tested)

Perhaps test_plots.py should be updated, but I'm actually not sure what a safe (and a platform independent) way of creating a file is (in a test suite).

@@ -53,7 +53,16 @@ def traceplot(trace, varnames=None, transform=lambda x: x, figsize=None,
>>> pymc3.traceplot(trace, ax=axs)

Creates own axes by default.

fname: str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fname : str

@twiecki
Copy link
Member

twiecki commented Jan 31, 2017

Not sure why this is better than just calling plt.savefig() directly or grabbing the figure reference and calling fig.save()?

@alexander-belikov
Copy link
Author

It's true that plt.savefig() works. Grabbing the figure reference is more difficult (in the master version only axis is returned by the function): figure() is either created in traceplot() or is assumed to exist outside and all operations are applied to ax.

As a user, I would like a function that outputs a figure, and much more often than not to file (sometimes one with hundreds and thousands of traces). The user of pymc3 does not even have to be aware of plt . Calling a function that saves the 'current' figure (plt.savefig()) in the scope different from where it was created (rather that 'this' figure) can lead to unexpected behavior.

A related issue that should addressed at some point is that the created figures should be closed eventually. Matplotlib will generate a corresponding warning if one calls traceplot() ~ 100 times.

@twiecki
Copy link
Member

twiecki commented Feb 1, 2017

What if instead we returned the figure and axis?

@twiecki
Copy link
Member

twiecki commented Feb 13, 2017

Closing this, I think returning the figure and axis is the better thing to do.

@twiecki twiecki closed this Feb 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants