我正在尝试运行 official website 中的基本 matplotlib
示例:
但是,当我运行代码时,我的 Python 解释器会抱怨并输出以下消息:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()
我已通过 matplotlib
安装了 pip3 install matplotlib
。
我当前的 python3
版本是 3.9.1,我的操作系统是 Ubuntu 20.04。
我已经尝试安装 tkinter,如 here 所述,但没有成功。 我应该怎么办?为什么会发生这种情况?
答案 0 :(得分:1)
请试试这些,如果有的话:
如果您使用的是 Jupyter Notebook
%matplotlib inline
确保你有 tkinter,安装 tkinter 后重新编译 python 解释器
试试:
import matplotlib
import matplotlib.pyplot as plt
plt.style.use('ggplot')
matplotlib.use( 'tkagg' )
x = [1, 5, 1.5, 4]
y = [9, 1.8, 8, 11]
plt.scatter(x,y)
plt.show()