'Mplot3D plot freezes when plotting in PyCharm Professional
Recently when I am doing MatPlotLib 3D plots in PyCharm, the debugging and the plot window are freezing when excuting the plt.show() command. In the top bar of the plot is mentioned (Not Responding). This happens both in PyCharm Community edition 2019 and PyCharm Professional 2021. I am running v3.8 of Python. If I execute plt.show(Block=True), the interactive 3D plot will come up, but I will need to close the figure to continue the debugging.
Does anyone have an idea how I can plot the figure with plt.show(), get up the interactive window, and continue debugging while still having the interactive window open? This worked in my previous version of Python v3.7, but the problem happened recently when upgrading to v3.8.
Solution 1:[1]
I recently faced the same issue when using matplotlib to plot. This seems to be related to a change in the order of precedence that matplotlib uses to pick its default backend. According to the matplotlibrc file that is bundled with the Python package, the order used to be
MacOSX Qt5Agg Gtk3Agg TkAgg WxAgg Agg
in previous versions (e.g., v3.4.2), while in more recent versions (e.g., v3.5.0) it has been be changed to
MacOSX QtAgg Gtk4Agg Gtk3Agg TkAgg WxAgg Agg
For me, setting the backend to Qt5Agg right after importing matplotlib in Python via
import matplotlib
matplotlib.use("Qt5Agg")
indeed solved the "Not responding" issue. Alternatively, we can specify it through the environment variable MPLBACKEND=Qt5Agg.
Likely, we could also set Qt5Agg as default backend in matplotlibrc either by modifying the bundled matplotlibrc file or by providing our own.
PS: Not sure whether the core issue that prevents the QtAgg backend from working correctly is in PyCharm, matplotlib, or PyQt...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
