【发布时间】:2021-11-01 16:08:22
【问题描述】:
我在 python3 的 tkinter 窗口中使用 matplotlib。该程序在我的编码机器上运行良好(在 Windows WSL 中运行的 ubuntu18.04)。不幸的是,我需要这个程序在我的 Raspberry Pi 4 上运行,它安装了 Ubuntu20.04 64bit 和发行版 Ubuntu Mate 1.24.0。 当我在 RPi 上运行我的程序时,我一调用就会出现分段错误
FigureCanvasTkAgg.draw()
尽管如此,我在其他程序中使用 matplotlib(使用 pyplot)并且它们运行良好。
详情:
- 这些是我的导入:
import tkinter as tk
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
- 这是我的程序所做的简要总结:
- 我有一个实现 tkinter 窗口的类;在构造函数中,我实例化了以下绘图变量:
self.figure = Figure(figsize=(5, 5), dpi=100)
self.subplot = self.figure.add_subplot(111)
self.canvas = FigureCanvasTkAgg(
self.figure, master=self.tkWindow)
- 那么,类有这个方法来更新绘图:
def updatePlot(self, x, y, title, xlabel, ylabel):
self.subplot.clear()
self.subplot.set_title(title)
self.subplot.set_xlabel(xlabel)
self.subplot.set_ylabel(ylabel)
self.subplot.plot(x, y, color='red', label='unfiltered')
self.subplot.legend(loc='upper right')
self.canvas.draw() # <- this is the line that causes the crash
self.canvas.get_tk_widget().grid(row=4, columnspan=5)
-
我的 Windows 机器上的版本:
- Ubuntu 18.04.5
- Python3 3.6.9
- Matplotlib 2.1.1
- Tkinter 0.1.0
-
我的 RPi 上的版本:
- Ubuntu 20.04.3
- Python3 3.8.10
- Matplotlib 3.3.4
- Tkinter 0.1.0
【问题讨论】:
-
你能告诉我们所有的分段错误输出吗?也请发minimal reproducible example。
-
当然,抱歉,如果我一开始没有包含它。我正在努力。
-
更新:我写了一个应该与我的代码相同的示例:该示例有效,我看不出它与我的原始程序有什么不同。无论如何,Clown Down 的解决方案是有效的,所以我会同意的!
标签: python-3.x matplotlib ubuntu tkinter segmentation-fault