【问题标题】:Plot doesn't show up in Python on OpenSUSE在 OpenSUSE 上的 Python 中不显示绘图
【发布时间】:2019-02-02 08:56:21
【问题描述】:

我想在 Python 中绘制给定的图表,但是该图表根本不显示。我使用以下代码:

import pylab as p

C = [1,2,3,4]
S = [10, 20, 30, 10]
p.plot(C,S)
p.show()

我怀疑这是因为我将 OpenSUSE 与 Wayland 一起使用。有谁知道解决方法,或者如何使用 Python 在 OpenSUSE Tumbleweed 中绘图?

我们将不胜感激所有帮助。

【问题讨论】:

    标签: python-3.x matplotlib plot


    【解决方案1】:

    在此here 上还有另一篇帖子,ImportanceofBeingErnest 给出了很好的回答,建议使用import matplotlib; matplotlib.use("TkAgg") 之前 import matplotlib.pyplot as plt。您可以在backends on the matplotlib site 上找到更多信息。 您可能仍然需要安装适当的 python-to-toolkit 包,例如。 python-tkinter 和 python3-tk,或者尝试已经安装的后端。例如,qt5agg 提供了一个选项以交互方式配置一些图形参数。

    【讨论】:

    • 这是为我做的。在导入pyplot 之前使用matplotlib.use() 确实很重要。
    【解决方案2】:

    在 Tumbleweed 中使用 Python 3.6

    打开 Yast 软件管理 选择 python3-matplotlib 我选择 python3-matplotlib-tk 作为后端然后安装

    这会安装:- python3-Cycler python3-kiwisolver python3-matplotlib python3-matplotlib-tk python3-numpy python3-olefile python3-枕头 python3-python-dateutil python3-pytz

    在 python 脚本中使用:- 导入 matplotlib matplotlib.use('TkAgg') 将 matplotlib.pyplot 导入为 plt 将 numpy 导入为 np

    为我工作。

    【讨论】:

      猜你喜欢
      • 2022-07-22
      • 1970-01-01
      • 2021-04-21
      • 2017-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多