Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass the "More than 20 figures have been opened." warning with the .. ipython directive #13620

Open
DominiqueMakowski opened this issue Apr 4, 2022 · 0 comments

Comments

@DominiqueMakowski
Copy link

Dear all,

I recently discovered the .. ipython directive and I am re-building my package's documentation from scratch with it, and it's great!

However, I ran into an issue. I have many functions and most of the examples produce some kind of figures, that I want to display in the docs. So I save them using the @savefig decorator. However, after I added another function, the documentation build started failing:

WARNING: 
>>>-------------------------------------------------------------------------
Warning in C:\Dropbox\RECHERCHE\N\NeuroKit\neurokit2\ecg\ecg_phase.py:docstring of neurokit2.ecg.ecg_phase.ecg_phase at block ending on line 37
Specify :okwarning: as an option in the ipython:: block to suppress this message
----------------------------------------------------------------------------
C:\Users\domma\AppData\Roaming\Python\Python39\site-packages\pandas\plotting\_matplotlib\core.py:386: 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`).
  fig = self.plt.figure(figsize=self.figsize)
<<<------------------------------------------------------------------------

(see building log here)

I believe the first warning is "spurious", as the function where it says there is an issue changes when I comment/uncomment other functions. I feel like the first warning is actually caused by the second, which complains once I have more than 20 figures.

Unfortunately, this leads to an overall build fail:

Exception occurred:
  File "C:\Users\domma\AppData\Roaming\Python\Python39\site-packages\IPython\sphinxext\ipython_directive.py", line 592, in process_input
    raise RuntimeError('Non Expected warning in `{}` line {}'.format(filename, lineno))
RuntimeError: Non Expected warning in `C:\Dropbox\RECHERCHE\N\NeuroKit\neurokit2\ecg\ecg_phase.py:docstring of neurokit2.ecg.ecg_phase.ecg_phase` line 37

Is there a way to bypass this max figures warning?

I thought of:

  • Adding a plt.close() after each figure but that would clutter the documentation quite a bit if that line is present after each figure.
  • Adding a :okwarning: specification, in each of the chunks, but I would like to keep warnings in case in the future some examples start to fail.

Is there a way to either close all the figures automatically after they are created?

Thanks for any pointers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant