[英]Interactive plotting in Pycharm debug console through matplotlib
I have a python script I'm trying to debug and I'm using Pycharm Community Edition version 2016.3.2.我有一个正在尝试调试的 python 脚本,我正在使用 Pycharm 社区版 2016.3.2 版。
What I'd like to do is make some plots in the debug console (which I activate by setting a breakpoint and starting the debugger), but the problem is that the plot simply doesn't show up.我想做的是在调试控制台中绘制一些图(我通过设置断点并启动调试器来激活它),但问题是该图根本不显示。
Some code to get a reproducible example of my problem is provided on the official matplotlib
documentation here , in particular this bit of code:在这里的官方matplotlib
文档中提供了一些代码来获得我的问题的可重现示例,特别是这段代码:
import matplotlib.pyplot as plt
plt.ion()
plt.plot([1.6, 2.7])
What I find strange is that if I open a new python console from inside pycharm, when executing this code pycharm pops up a new window showing the plot, but this doesn't happen if I paste the same code in the "debug" console.我觉得奇怪的是,如果我从 pycharm 内部打开一个新的 python 控制台,当执行此代码时,pycharm 会弹出一个显示绘图的新窗口,但如果我将相同的代码粘贴到“调试”控制台中,则不会发生这种情况。
In both cases, I get the following output in the console在这两种情况下,我都在控制台中得到以下输出
I found a potentially related post here , but frankly I can't tell if the two problems reduce to the same issue.我在这里找到了一个可能相关的帖子,但坦率地说,我不知道这两个问题是否归结为同一个问题。
python 3.8.12
, matplotlib 3.4.3
, PyCharm 2021.2.3 (Professional Edition)
在python 3.8.12
、 matplotlib 3.4.3
、 PyCharm 2021.2.3 (Professional Edition)
mpl.use('Qt5Agg')
mpl.use('TkAgg')
import matplotlib.pyplot as plt
import matplotlib as mpl
# mpl.use('Qt5Agg') # interactive mode works with this, pick one
mpl.use('TkAgg') # interactive mode works with this, pick one
# Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
explode = (0, 0.1, 0, 0)
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
ax1.axis('equal')
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.