首页 > 解决方案 > plotnine:用户警告:在主线程之外启动 Matplotlib GUI 可能会失败

问题描述

我正在尝试使用 plotnine 生成一些图表。我导入所需的库:

from plotnine import *
from plotnine.data import mpg

然后,如果我在 PyCharm 中运行以下代码,我会收到一条警告消息,窗口图会显示“No answer”消息,我被迫重新启动 python 终端:

(ggplot(mpg)         # defining what data to use
 + aes(x='class')    # defining what variable to use
 + geom_bar(size=20) # defining the type of plot to use
)

<ggplot: (150517199824)>
C:\Users\alvaromc317\miniconda3\envs\general\lib\site-packages\plotnine\ggplot.py:363: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.

但是,如果我从 windows cmd 终端启动一个 python 终端并运行与以前相同的脚本,我不会收到任何错误消息,并且我可以看到没有问题的图。

发生了什么,如何在 pycharm 中使用 plotnine?

如果需要,我使用 Windows 10 机器和基于 miniconda 的 python 3x 工作。

标签: python-3.xpycharmplotnine

解决方案


我遇到了类似的问题,但是在使用 PyCharm 的商业添加的 MacOS 上。

这个 github 问题这个 JetBrains 问题来看,它看起来可能与 PyCharm 错误有关。


推荐阅读