gpt4 book ai didi

python - UserWarning : Matplotlib is currently using agg, 所以无法显示数字

转载 作者:行者123 更新时间:2023-12-02 02:19:47 29 4
gpt4 key购买 nike

我正在尝试运行来自 official website 的基本 matplotlib 示例:

但是,当我运行代码时,我的 Python 解释器会报错并输出以下消息:

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()

我已经通过 pip3 install matplotlib 安装了 matplotlib。我当前的 python3 版本是 3.9.1,我的操作系统是 Ubuntu 20.04。

我已经尝试安装 tkinter,如前所述 here ,没有成功。我应该怎么办?为什么会这样?

最佳答案

请试试这些,如果有适合你的话:

  1. 如果您使用的是 Jupyter Notebook

     %matplotlib inline 
  2. 确保你有tkinter,安装tkinter后重新编译python解释器

  3. 尝试:

     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()

关于python - UserWarning : Matplotlib is currently using agg, 所以无法显示数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66606614/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com