Thanks to visit codestin.com
Credit goes to github.com

Skip to content

plt.ioff() not supressing figure generation #14950

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

Closed
Yoshi2112 opened this issue Aug 1, 2019 · 9 comments
Closed

plt.ioff() not supressing figure generation #14950

Yoshi2112 opened this issue Aug 1, 2019 · 9 comments
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@Yoshi2112
Copy link

Yoshi2112 commented Aug 1, 2019

Bug report

Bug summary
Usual behaviour for supressing plots (by enabling plt.ioff()) no longer working since update to latest version of conda.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

x = np.random.rand(10)
y = np.random.rand(10)

plt.ioff()
plt.plot(x, y)

Actual outcome
In Spyder IDE, still generates figure window.

Expected outcome
Figure window should not appear. plt.ioff() should disable interactive mode, and require a plt.show() call to generate figure window.

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.1.0
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.3
  • Jupyter version (if applicable):
  • Other libraries: numpy 1.16.4

conda

Default channel (via https://www.anaconda.com/distribution/ )

@WeatherGod
Copy link
Member

WeatherGod commented Aug 1, 2019 via email

@ImportanceOfBeingErnest
Copy link
Member

Spyder does not have its own backend (PyCharm has, though).
However, spyder has a "Support for grahics (Matplotlib)" mode, which is probably turned on by default.

image

Many people like this mode, because it allows to choose a backend on a by-file- or by-project basis etc., but support for consequences of using this should probably directed towards Spyder.

@Yoshi2112
Copy link
Author

@ImportanceOfBeingErnest

If I force inline plots by disabling Matplotlib support in Spyder, the interactive mode works correctly. Inline also works correctly when manually selected as the graphics backend.

The other modes don't work as I'd expect. I'd always used the "Automatic" setting, which would probably be Qt5. Manually selecting Qt5 had the behaviour described in the OP - plt.ioff() failed to suppress the generation of a figure window.

Of the other two modes, Qt4 failed to run because Qt5 was running (?), and Tkinter was successfully suppressed, but failed to display a plot when interactive mode was selected. A figure window was generated, but frozen. This might be an issue with missing modules or something though? I'm not exactly a dev.

Is this a problem with matplotlib? Or perhaps an issue with the Spyder IDE failing to adhere to the interactive mode settings?

@ccordoba12
Copy link

ccordoba12 commented Aug 2, 2019

Chiming in in behalf of Spyder. We set the Matplotlib backend using the %matplotlib IPython magic, so if there's a problem it's with that magic.

@ImportanceOfBeingErnest
Copy link
Member

Indeed it doesn't look like a Spyder issue. I was able to reproduce solemnly on the Ipython QtConsole, running

image

Now it turns out this is indeed a matplotlib issue.
It bisects to #13664 ("Backport PR #12637 on branch v3.1.x (Tell IPython the correct GUI event loop to use for all backends.)"), and hence originates from

#12637 ("Tell IPython the correct GUI event loop to use for all backends.")

@ImportanceOfBeingErnest ImportanceOfBeingErnest added this to the v3.1.2 milestone Aug 2, 2019
@ImportanceOfBeingErnest ImportanceOfBeingErnest added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Aug 2, 2019
@tacaswell
Copy link
Member

Suspect that ipython/ipython#11837 is also related.

@tacaswell
Copy link
Member

I suspect that if you call plt.ioff() after you have created the first figure it will work as expected.

@ImportanceOfBeingErnest
Copy link
Member

Yes, but that's not really an option if you want to run your whole code in one cell, like e.g. spyder does.

@Carreau
Copy link
Contributor

Carreau commented Aug 5, 2019

See #14979 for the fix of the IPython side issue; and thomas is right that the piece of code that is responsible for the IPython-side-issue seem to also enable matplotlib gui integration and switch back to interactive.

It seem to be triggered as a side effect of import matplotlib.pyplot as plt So we should likely detect that the %matplotlib magic has been called and not trigger the ip.enable_maplotlib()

@anntzer anntzer closed this as completed in d66a760 Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

No branches or pull requests

6 participants