SourceForge logo
SourceForge logo
Menu

[Matplotlib-users] Adding a ready figure to pyplot.

From: Anton A. <ant...@gm...> - 2012年07月29日 12:15:16
Hi,
I am writing a module which should, among other things, output images, and it 
should work both in interactive mode and when imported as a script.
In order for the plotting behavior to be clean, I would like to prepare the 
figure separate from pyplot. The reason for this, is that the figure is drawn in 
a non-interactive loop, and I don't want to show all the steps as they go. 
Moreover, for some reason with ipython inline backend the figure is rendered 
twice for no obvious reason. So the preferred behavior of my plotting function 
(when pyplot output is requested) should be similar to:
fig = matplotlib.figure.Figure()
ax = fig.add_subplot(111)
ax.plot([1,2,3])
matplotlib.pyplot.<ADD_FIGURE>(fig)
The best approximation to this that I was able to find so far is to use the 
following dirty hack (although none of the attributes I use are _private!):
f = plt.figure()
fig.canvas = f.canvas
f.canvas.figure = fig
However this is still problematic: if the interactive mode is on, then rendering 
of the figure will still be called after these two attribute. Moreover in 
IPython notebook without inline plotting it will result in an opened GUI window, 
but GUI mainloop not running.
So here's my question: what's the best way to achieve the behavior that I want?
Thank you,
Anton

View entire thread

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /