Update FAQ re: batch/webserver use.#13062
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.
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.
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.
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.
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.
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.
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