Subject: Re: bug#62783: [PATCH] comint-mime: Add Matplotlib support in the standard interpreter

From: James Thomas <[email-masked]>
Date: Thu, 20 Apr 2023 10:47:58 +0530

Augusto Stoffel wrote:

> Also, it seems I also need to call plt.close() manually, otherwise
> subsequent calls to plt.plot add to the figure instead of starting a
> new one.

pyplot.show displays _all_ open 'figure's. If you want to display a
particular figure, fig.show() can be used. Also, pyplot.close can close
figures selectively.

Subsequent calls of pyplot.plot add to the 'current' figure which it
keeps track of (and that can be switched).

>   >>> plt.plot([1,2,1])
>   [<matplotlib.lines.Line2D object at 0x7ffb2cca0a10>]
>
> I still need to call plt.show() afterwards to see the image. This is
> better than nothing, but would be nice if the extra step wasn't
> necessary.

I guess it would be straightforward to implement a pretty-printer for
the Line2D object that would call its figure.show, but for the sake of
completeness this would have to be done also for every kind of element
in a figure other than lines - like axes or legends.

Also, personally, I would find it annoying if every change I make to a
figure would result in a redisplay. Sometimes I want to accumulate
changes before showing the result.

(I'm rather new to all this myself and the above is only to the best of
my knowledge)

--