0

I like that plots are displayed within the output of an ipython kernel. However, it would be nice to produce the figure across multiple cells, and call plt.show() (or similar) at the end to display it.

As it stands, when using the inline backend, using PDB to set a breakpoint on plt.close, I get the following stack trace:

  [...]
-> return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  [...]\ipython\core\interactiveshell.py(2664)run_cell()
-> self.events.trigger('post_execute')
  [...]\ipython\core\events.py(88)trigger()
-> func(*args, **kwargs)
  [...]\pylab\backend_inline.py(113)flush_figures()
-> return show(True)
  [...]\pylab\backend_inline.py(42)show()
-> matplotlib.pyplot.close('all')

I believe I would like to prevent flush_figures from being called. Is there any way to remove this event from ipython's "post_execute" event? While I'm aware that one option is to switch to another backend (I've seen some people suggest %matplotlib agg), I'm hoping to keep the current behavior of displaying the plots, but only when I call plt.show(). Other methods of achieving this, such as an alternate backend that doesn't call the flush_figures event are also welcome.

Kaia
  • 862
  • 5
  • 21
  • 1
    Have you tried the solution "B" [posted in this answer](https://stackoverflow.com/a/45766059/565489)? Using `%config InlineBackend.close_figures=False` seems to be the solution to me. – Asmus Sep 09 '20 at 05:41
  • 1
    My googling is not up-to-par. Thanks. This works for me. I can't close-as-duplicate because of the bounty, I'm not sure what the proper procedure is here, but if you want to post an answer to that effect I'd be happy to accept it. – Kaia Sep 09 '20 at 19:01
  • 1
    Thanks, but I'd rather see this question closed than getting that bounty :-) Consequently, I've flagged this question for "moderator intervention", as [suggested in this meta question](https://meta.stackoverflow.com/questions/252192/how-can-i-close-a-question-that-has-an-active-bounty). If this doesn't help I'd suggest you just wait until the bounty runs out and close it then. – Asmus Sep 10 '20 at 06:40

0 Answers0