-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Update FAQ re: batch/webserver use. #13062
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
Conversation
The previous FAQ entry re: not having a window appear is far too complicated (in practice, just not calling show() is good enough, especially now that we'll select a noninteractive backend when working headlessly anyways. The previous FAQ entry re: webserver use is also far too complicated; again the choice of backend is now automatic, and we don't need to select a priori what kind of output will be used (Matplotlib will switch the underlying backend automatically).
import matplotlib.pyplot as plt | ||
plt.plot([1,2,3]) | ||
plt.savefig('myfig') | ||
Simply do not call `~matplotlib.pyplot.show`, and directly save the figure to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work in an interactive terminal if we are in 'interactive' mode (as we call show()
implicitly on figure creation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough (that's not a use case I thought about). Do you want to recommend calling ioff(), or use('agg')? (I admit I never ever use ioff(), so heh.)
|
||
import matplotlib.pyplot as plt | ||
plt.plot([1, 2, 3]) | ||
plt.savefig('myfig.png') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a new problem, but this should probably include a note about closing the figure or you will eventually run out of memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually perhaps the whole thing should just point to the same approach as the webserver solution (i.e. call the Figure() ctor) outside of pyplot. Thoughts?
In general, the simplest solution when using Matplotlib in a web server is | ||
to completely avoid using pyplot (pyplot maintains references to the opened | ||
figures to make `~.matplotlib.pyplot.show` work, but this will cause memory | ||
leaks unless the figures are properly closed). Since Matplotlib 3.1, one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads like saving to the buffer is a feature of 3.1 (rather than the more terse version of getting a functional Figure
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to push a reword.
Merging as improvement... |
The previous FAQ entry re: not having a window appear is far too
complicated (in practice, just not calling show() is good enough,
especially now that we'll select a noninteractive backend when working
headlessly anyways.
The previous FAQ entry re: webserver use is also far too complicated;
again the choice of backend is now automatic, and we don't need to
select a priori what kind of output will be used (Matplotlib will switch
the underlying backend automatically).
Closes #12628.
PR Summary
PR Checklist