[Matplotlib-users] mplcairo multipage pdf and too many figures open

Joshua Klein mobiusklein at gmail.com
Fri Aug 16 07:24:53 EDT 2019


`pdf.savefig` returns None (it has no explicit return value), which is a
False-y value. This causes the `and` expression to short-circuit and the
right-hand-side expression is never evaluated. You'll need to call them
separately.

On Fri, Aug 16, 2019 at 7:17 AM Neal Becker <ndbecker2 at gmail.com> wrote:

> I recoded as:
>
>     if pdf: pdf.savefig (fig) and plt.close(fig)
>
> And I still get the same warning message.
>
> On Fri, Aug 16, 2019 at 4:46 AM Antony Lee
> <antony.lee at institutoptique.fr> wrote:
> >
> > Hi,
> > You can probably either call plt.close(fig) after savefig to close the
> figure (likely best), or adjust rcParams["figure.max_open_warning"] to a
> large enough number (at the risk of running out of memory).
> > Antony
> >
> > On Fri, Aug 16, 2019 at 12:44 AM Neal Becker <ndbecker2 at gmail.com>
> wrote:
> >>
> >> I've been using mplcairo multipage pdf.  The pattern I use is:
> >>
> >> from mplcairo.multipage import MultiPage
> >> cm = MultiPage(ap_args.output)
> >>
> >> with cm as pdf:
> >>   fig,ax = plt.subplots()
> >>   do something
> >>   pdf.savefig(fig)
> >>
> >>   fig2,ax2 = plt.subplots()
> >>   do something
> >>   pdf.savefig(fig2)
> >> ...
> >>
> >> after 20 figures:
> >> RuntimeWarning: More than 20 figures have been opened. Figures created
> >> through the pyplot interface (`matplotlib.pyplot.figure`) are retained
> until
> >> explicitly closed and may consume too much memory. (To control this
> warning,
> >> see the rcParam `figure.max_open_warning`).
> >>
> >> What is the proper way to use mplcairo.multipage to avoid this issue?
> >>
> >> Thanks,
> >> Neal
> >>
> >> _______________________________________________
> >> Matplotlib-users mailing list
> >> Matplotlib-users at python.org
> >> https://mail.python.org/mailman/listinfo/matplotlib-users
>
>
>
> --
> Those who don't understand recursion are doomed to repeat it
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190816/df0f74ae/attachment.html>


More information about the Matplotlib-users mailing list