2

When I call pyplot.show(block=True) a window with the correct plot appears. When trying to manually close it, the window closes but the program won't continue to run (like it's still blocked).

For instance, the following program will display the plot window and print Before, but after manually closing the window, the program still seems blocked, and After is not printed.:

plt.plot(x,y)
print("Before")
plt.show(block=True)
print("After")

I work with the latest matplotlib version (2.1.2) using the interactive TkAgg backend on Python 3.5.2.

Update - Additional info: I work with Pycharm 2017.2 on Ubuntu (VM on Windows host)

Itay
  • 16,601
  • 2
  • 51
  • 72
  • 1
    weird. works for me with python 3.6 and the latest matplotlib version (actually without block = True) – Banana Feb 07 '18 at 08:40
  • Interactive behaviour is imho not so much dependent on the version of matplotlib and Python, but the IDE/interpreter used. Loads of threads about difficulties [with Eclipse/PyDev for instance](https://stackoverflow.com/questions/13440956/interactive-matplotlib-through-eclipse-pydev). – Mr. T Feb 07 '18 at 09:01
  • The usual behaviour of the code shown is indeed that it prints "After" after you close the plot. If that does not work for you, and you want help with that provide all necessary information about how and where you run this code. Also a screenshot might help. See [mcve]. – ImportanceOfBeingErnest Feb 07 '18 at 09:40
  • Is this on a mac? – Thomas Kühn Feb 07 '18 at 10:47
  • @ThomasKühn I run this on Ubuntu. – Itay Feb 07 '18 at 11:11
  • @ImportanceOfBeingErnest I can't see what more information a screenshot could give. I described the full behavior. – Itay Feb 07 '18 at 11:11
  • @Itay Ok, I have experienced this before on mac, this is why I asked. I've never found an actual fix to it, but a workaround, where I would set `block=False` and then hold the program by doing something like `input('press to continue)' so that the program waits for input from the terminal. See for instance [here](https://stackoverflow.com/a/44242084/2454357). – Thomas Kühn Feb 07 '18 at 11:15
  • 1
    At least I can say it works fine with pycharm 2017.1 on windows, see [this screenshot](https://i.stack.imgur.com/Y44CN.gif). – ImportanceOfBeingErnest Feb 07 '18 at 13:23
  • @ImportanceOfBeingErnest Thanks, added following your advice – Itay Feb 07 '18 at 13:30

1 Answers1

0

Solved by unselecting the "Use IPython if available" checkbox in PyCharm's settings.

IPython

Itay
  • 16,601
  • 2
  • 51
  • 72