Matplotlib 和 Pyplot 的导入问题(Python / Tkinter)

亚当·戴维斯

我遇到了无法调用“matplotlib”的“pyplot”元素的问题。从下面的代码中,您可以看到我必须为 mattplotlib 元素添加一个“TkAgg”才能工作,这是一个常见问题。

import matplotlib
matplotlib.use("TkAgg")

但是,现在我无法将 '.pyplot' 添加到导入中。我尝试了以下方法:

import matplotlib.pyplot as plt
plt.use("TkAgg")

但这给了我错误:

AttributeError: 模块 'matplotlib.pyplot' 没有属性 'use'

我怎样才能解决这个问题,因为我的代码需要 pyplot 才能运行,但我无法在仍然必须使用“.use("TkAgg")的情况下弄清楚如何导入它。

我正在运行 Python 3.6.2 并且我正在使用 Tkinter 来开发我的程序

存在的重要性欧内斯特

这是完全不同的两件事。您导入matplotlib可以设置后端。然后您仍然需要导入pyplot才能在之后使用它。

import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
# ... rest of code

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

导入matplotlib和matplotlib.pyplot有什么区别?

使用cxFreeze导入matplotlib.pyplot和BeautifulSoup

Python Matplotlib pyplot直方图

尝试在Arch Linux中导入matplotlib.pyplot时出现tkinter错误

无法导入“ matplotlib.pyplot”

matplotlib.pyplot.xticks()问题

Matplotlib Pyplot ImageGrid 图问题

在 python 中将 matplotlib.pyplot 作为 plt 导入的问题(Anaconda - Spyder)

在matplotlib.pyplot和numpy中递减

在饼图上显示带有图例的数字-Tkinter,Pyplot,Matplotlib

导入matplotlib.pyplot-fc-list挂起

PyCharm导入matplotlib.pyplot显示错误

导入matplotlib.pyplot作为plt失败

导入matplotlib.pyplot时嵌入式python崩溃

为 python matplotlib.pyplot 等高线图指定 x 和 y 范围

matplotlib.pyplot.his和基本的python:我无法理解to实例之间的区别

matplotlib.pyplot.contour 有问题

是“从matplotlib将pyplot导入为plt” ==“从matplotlib.pyplot导入为plt”?

导入matplotlib.pyplot时发生Matplotlib TypeError

Python,matplotlib.pyplot无法看到线图

Python matplotlib.pyplot不显示图

Python的matplotlib.pyplot.quiver如何工作?

python中的分组图表(matplotlib.pyplot)

关于 matplotlib.pyplot.matshow 和 np 矩阵对象的一些相关问题: plotting "None"/"nan", and x axis offset

参数s中带有matplotlib.pyplot.scatter的matplotlib.pyplot问题

如何使用matplotlib和pyplot正确实现QThread

matplotlib pyplot - 如何组合多个 y 轴和多个图

Matplotlib pyplot-刻度控制和显示日期

使用pandas和matplotlib.pyplot创建图例