Plot freezes when calling pyplot's close() command in PyCharm's ipython console

已回答

The problem is the following: whenever I try to close a figure in PyCharm's ipython console using plt.close(fig), the figure freezes. This does not happen in the ipython console started from the terminal.

Example code:

from matplotlib import pyplot as plt
fig = plt.figure()
plt.show(block=False) # This line is useless in pycharm since the figure is shown after the previous line
plt.close(fig)

At this point, the newly created figure does not close and freezes instead. I thought that this might be due to the awkward interacting mode that PyCharm uses. So I tried to set it off via

plt.ioff()

but nothing has changed, the figure still pops up without requiring plt.show(), and freezes when invoking plt.close(fig).

The exact same code works as it should in the ipython console of my terminal. I have spent two hours yesterday searching for a solution to my problem but I could not make it work.

OS: MacOS Sierra

Reproducibility: this problem is not related to a corrupted virtualenv; I reproduced it on two different environments with different versions of python and matplotlib.

1

Hello! Unfortunately, I'm not able to reproduce the problem locally. What PyCharm version do you use?

0
Avatar
Permanently deleted user

Hi Anna,

There you go:

0
Avatar
Permanently deleted user

It's real lifehack if you using pyplot in PyCharm. Thanks.

0

请先登录再写评论。