Skip to content

don't let matplotlib pop up all opened windows #10972

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
Xunius opened this issue Apr 6, 2018 · 13 comments
Closed

don't let matplotlib pop up all opened windows #10972

Xunius opened this issue Apr 6, 2018 · 13 comments
Labels
GUI: Qt status: needs clarification Issues that need more information to resolve.

Comments

@Xunius
Copy link

Xunius commented Apr 6, 2018

Bug report

Bug summary

My problem is kind of the opposite to this stackoverflow question: Matplotlib plt.show() method does not pop out the window that my matplotlib always pop up ALL the previously opened windows together with the new window plt.show(block=False) opens. This gets annoying when I need to debug the code by generating some plots, Alt-Tab to switch back to code and generate some more plots. If only the last plot window is brought to the front, I need only 1 hit of Alt-Tab, now there will be a long list of tab-icons to go through before I get back to the code window.

I'm pretty sure it didn't behave like this before, probably after I reinstalled Anaconda and got a different version of matplotlib.

The backend it currently uses is qt5agg, changing to Tkagg solves the problem.

Matplotlib version

  • Operating system: Manjaro linux
  • Matplotlib version: 2.1.2=py27h0e671d2_0
  • Matplotlib backend (print(matplotlib.get_backend())): qt5agg
  • Python version: 2.7.14 from Anaconda
  • Jupyter version (if applicable):
  • Other libraries:

Installed via conda install matplotlib

@jklymak
Copy link
Member

jklymak commented Apr 6, 2018

This needs a minimal example to see what you are talking about.

@jklymak jklymak added the status: needs clarification Issues that need more information to resolve. label Apr 6, 2018
@dstansby
Copy link
Member

dstansby commented Apr 6, 2018

It also looks like you're using an old version of Matplotlib. Could you upgrade to version 2.2 and let us know if it is still a problem?

@Xunius
Copy link
Author

Xunius commented Apr 7, 2018

@dstansby Yes 2.2 gives the same behavior, opening one new window also brings all other windows to the front. And again changing to TkAgg backend works.

@timhoffm
Copy link
Member

timhoffm commented Apr 7, 2018

I cannot reproduce this behavior on master. Please give a step-by-step example what you are doing.

@efiring
Copy link
Member

efiring commented Apr 7, 2018

This sounds like the kind of thing that might not be under our control; it results from the interaction between the gui library and the window manager.

@Xunius
Copy link
Author

Xunius commented Apr 9, 2018

Thanks for all the feedbacks, I didn't think this would get any more attention as it's not a crucial problem and I already found a workaround.

This happened after I did a fresh install of Manjaro (17.1.6, with Cinnamon 3.6.6) and installed a newer anaconda (4.4.10).
Then steps I took:

  1. create a new conda environment, and install a bunch of modules. Here is the complete list:
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
backports=1.0=py27h63c9359_1
backports.functools_lru_cache=1.5=py27_1
backports_abc=0.5=py27h7b3c97b_0
basemap=1.0.7=np113py27_0
bokeh=0.12.14=py27_0
ca-certificates=2018.03.07=0
cdat-lite=6.0.1=py27_3
certifi=2018.1.18=py27_0
click=6.7=py27h4225b90_0
cloudpickle=0.5.2=py27_1
curl=7.55.1=0
cycler=0.10.0=py27hc7354d3_0
dask=0.17.1=py27_0
dask-core=0.17.1=py27_0
dbus=1.12.2=hc3f9b76_1
decorator=4.2.1=py27_0
distributed=1.21.1=py27_0
expat=2.2.5=he0dffb1_0
fontconfig=2.12.4=h88586e7_1
freetype=2.8=hab7d2ae_1
functools32=3.2.3.2=py27h4ead58f_1
futures=3.2.0=py27h7b459c0_0
fuzzywuzzy=0.16.0=py_0
geos=3.5.0=0
glib=2.53.6=h5d9569c_2
gst-plugins-base=1.12.4=h33fb286_0
gstreamer=1.12.4=hb53b477_0
hdf4=4.2.13=0
hdf5=1.10.1=2
heapdict=1.0.0=py27_2
icu=58.2=h9c2bf20_1
imageio=2.2.0=py27hf108a7f_0
intel-openmp=2018.0.0=hc7b2577_8
jinja2=2.10=py27h4114e70_0
jpeg=9b=h024ee3a_2
kiwisolver=1.0.1=py27hc15e7b5_0
krb5=1.14.2=0
libedit=3.1=heed3624_0
libffi=3.2.1=hd88cf55_4
libgcc=7.2.0=h69d50b8_2
libgcc-ng=7.2.0=h7cc24e2_2
libgfortran=3.0.0=1
libgfortran-ng=7.2.0=h9f7466a_2
libnetcdf=4.4.1.1=10
libpng=1.6.34=hb9fc6fc_0
libssh2=1.8.0=2
libstdcxx-ng=7.2.0=h7a57d05_2
libtiff=4.0.9=h28f6b97_0
libxcb=1.12=hcd93eb1_4
libxml2=2.9.7=h26e45fe_0
locket=0.2.0=py27h73929a2_1
markupsafe=1.0=py27h97b2822_1
matplotlib=2.2.2=py27h0e671d2_0
mkl=2018.0.1=h19d6760_4
msgpack-python=0.5.5=py27h6bb024c_0
ncurses=6.0=h9df7e31_2
networkx=2.1=py27_0
numpy=1.13.3=py27h3dfced4_2
olefile=0.45.1=py27_0
openssl=1.0.2o=h20670df_0
packaging=16.8=py27h5e07c7c_1
pandas=0.22.0=py27hf484d3e_0
partd=0.3.8=py27h4e55004_0
pcre=8.41=hc27e229_1
pillow=5.0.0=py27h3deb7b8_0
pip=9.0.1=py27_5
psutil=5.4.3=py27h14c3975_0
pyparsing=2.2.0=py27hf1513f8_1
pyqt=5.6.0=py27h4b1e83c_5
pyspharm=1.0.9=py27_2
python=2.7.14=h1571d57_29
python-dateutil=2.6.1=py27h4ca5741_1
python-levenshtein=0.12.0=py27_0
pytz=2018.3=py27_0
pywavelets=0.5.2=py27hecda097_0
pyyaml=3.12=py27h2d70dd7_1
qt=5.6.2=hd25b39d_14
readline=7.0=ha6073c6_4
scikit-image=0.13.1=py27h14c3975_1
scikit-learn=0.19.1=py27h445a80a_0
scipy=1.0.0=py27hf5f0f52_0
setuptools=38.5.1=py27_0
singledispatch=3.4.0.3=py27h9bcb476_0
sip=4.18.1=py27he9ba0ab_2
six=1.11.0=py27h5f960f1_1
sortedcontainers=1.5.9=py27_0
sqlite=3.22.0=h1bed415_0
ssl_match_hostname=3.5.0.1=py27h4ec10b9_2
subprocess32=3.2.7=py27h373dbce_0
tblib=1.3.2=py27h51fe5ba_0
tk=8.6.7=hc745277_3
toolz=0.9.0=py27_0
tornado=4.5.3=py27_0
wheel=0.30.0=py27h2bc6bb2_1
windspharm=1.5.1=py27_0
xz=5.2.3=h55aa19d_2
yaml=0.1.7=had09818_2
zict=0.1.3=py27h12c336c_0
zlib=1.2.11=ha838bed_2
  1. Enter an interactive python session, plot just about anything in matplotlib, like this:
import numpy
import matplotlib.pyplot as plt
x=numpy.linspace(0,10,50)
y=numpy.sin(x)
fig=plt.figure();ax=fig.add_subplot(111);ax.plot(x,y);plt.show(block=False)

Then a new window pops as expected. Repeat the last line a few times, each time a new window opens, it also brings all existing figure windows to the front.

While using Tkagg backend, it only brings the newly opened window to the front, so a single Alt-Tab brings back the terminal window where I can continue the debugging.

It could be the interaction with the window manager as @efiring said, because I moved onto a new system and a new conda (probably new matplotlib as well) at the same time.

@jklymak
Copy link
Member

jklymak commented Apr 9, 2018

I'm not really following this problem. On my Mac, the terminal is a separate application from the backend. If a figure takes focus, the graphics backend is the front application. If I want to switch back to the terminal and can command-tab to get the terminal application back. If I want to see other figures I can scroll through them with command-`.

On your machine is the terminal not a different application from the python output windows? Are you doing this inside some sort of IDE?

Regardless, I'm not at all convinced this has anything to do with Matplotlib, and am tempted to close unless you think there is something we should be doing on our end.

@jklymak jklymak closed this as completed Jul 9, 2018
@Pritam987
Copy link

I am also facing the same prblm. Pls hlp.
IMG_20211008_003338

@QuLogic
Copy link
Member

QuLogic commented Oct 7, 2021

If you've run %matplotlib inline, that seems a problem for VSCode, not us.

@moefear85
Copy link

moefear85 commented Mar 2, 2025

Hi,

I would just like to clarify, using the following test script:

import matplotlib
from matplotlib.figure import Figure
from matplotlib.axes import Axes
from matplotlib.pyplot import (show,figure,subplot,subplots,pause,connect)
from matplotlib.backend_bases import MouseEvent,PickEvent,LocationEvent

matplotlib.use("TkAgg")

f=figure("foo")
axes=f.add_axes((0,0,1,1))
line=axes.plot((0,1),(0,1),picker=True)

def on_pick(event : PickEvent):
    print("on_pick",event)

def on_figure_enter(event : LocationEvent):
    print("on_figure_enter",event)

def on_motion_notify(event : MouseEvent):
    print("on_motion_notify",event)

def on_button_press(event : MouseEvent):
    print("on_button_press",event)

connect("pick_event", on_pick)
connect("figure_enter_event", on_figure_enter)
connect("motion_notify_event", on_motion_notify)
connect("button_press_event", on_button_press)
show(block=False)
while True:
    pause(1)
    #print("foo")

without the matplotlib.use("TkAgg") statement, then once the popup opens, it keeps popping back up after minimizing every time pause() is called, which is once per second in this case, and that is very annoying. It would be nice if the documentation hints to others that adding the mentioned statement resolves this issue, such that once minimized, the popup remains minimized until next explicit unminimize.

I would also like to express appreciation that matplotlib is designed to allow such rapid prototyping without having to deal with GUI/threading concepts while still being able to handle events hence make the plots interactive. I know it would be simpler to use blocking mode and perform all tasks in the event handlers, but it is nice to have the choice.

@jklymak
Copy link
Member

jklymak commented Mar 2, 2025

Maybe it's possible that tkagg has a different behaviour for focus than qt5agg for what windows it pops to the top? Maybe there is a setting we can control that governs this behaviour?

@moefear85
Copy link

moefear85 commented Mar 2, 2025

I'm not at my pc now, but I use KDE ou Kubuntu. In Desktop/workspace settings, there are options to control how willingly/reluctantly focus can get stolen by apps. I guess different backends behave inconsistently for any given level of focus-grab prevention.

@greglucas
Copy link
Contributor

There is an rcParam figure.raise_window to control this behavior now: https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.3.0.html#rcparams-for-controlling-default-raise-window-behavior
xref to a similar issue: #22939

Please open a new issue with a reproducible example demonstrating what behavior is going wrong with details of what is happening vs what is expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI: Qt status: needs clarification Issues that need more information to resolve.
Projects
None yet
Development

No branches or pull requests

9 participants