Python matplotlib 代码挂在 plt.plot() 上

问题描述 投票:0回答:2

当我尝试使用 matplotlib 中的某些函数时,我的代码卡在这些函数上。例如,如果我尝试运行

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()

x = np.random.randint(0, 10, 10)
y = np.random.randint(0, 10, 10)

plt.plot(x, y)
plt.show()

它成功运行了 plt.figure(),但代码的执行卡在了 plt.plot(x, y) 处。不会产生错误代码,并且我无法使用 ctrl+c 中断执行。

我使用 Linux Mint 5.4.0-70-generic,并使用 miniconda 进行 python 安装。我已经安装了 python3.9 和最新的 matplotlib 和 numpy 包。我已经完全重新安装了 conda 和 python 使用 tsveti_iko 的答案(我以前的版本是 python3.8,它给出了完全相同的问题)。直到今天,一切都很顺利。

编辑:在它停止工作之前我做的唯一一件事是我使用 apt-get update 和 apt-get Upgrade 更新了我的操作系统。但我不知道这是否会导致我的上述问题。

如果我使用

import logging
logging.basicConfig(level=logging.DEBUG)

我得到以下输出:

DEBUG:matplotlib:matplotlib data path: 
/home/sjoerd/miniconda3/lib/python3.9/site-packages/matplotlib/mpl-data
DEBUG:matplotlib:CONFIGDIR=/home/sjoerd/.config/matplotlib
DEBUG:matplotlib:matplotlib version 3.4.3
DEBUG:matplotlib:interactive is False
DEBUG:matplotlib:platform is linux
DEBUG:matplotlib:loaded modules: [(whole list of modules loaded, not shown here)]
DEBUG:matplotlib:CACHEDIR=/home/sjoerd/.cache/matplotlib
DEBUG:matplotlib.font_manager:Using fontManager instance from /home/sjoerd/.cache/matplotlib/fontlist-v330.json
DEBUG:matplotlib.pyplot:Loaded backend qt5agg version unknown.
DEBUG:matplotlib.pyplot:Loaded backend Qt5Agg version unknown.
python matplotlib
2个回答
2
投票

这确实是一个非常具体的问题。对于我的工作,我需要安装 citrix 工作区。不知怎的,这干扰了 matplotlib。卸载citrix客户端彻底解决问题。


0
投票

我不知道为什么,但

plt.show(block=True)
对我有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.