Ubuntu Mate 上的 Tkinter 分段错误中的 Matplotlib

Matplotlib in Tkinter segmentation fault on Ubuntu Mate

我在 python3 上的 tkinter window 中使用 matplotlib。该程序在我的编码机上运行良好(ubuntu18.04 运行ning windows WSL)。不幸的是,我需要这个程序在我的 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
        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)

我的 Raspberry Pi 3 B+ 和 Raspbian 运行 也遇到了同样的问题。

尝试将 FigureCanvasTkAgg.draw() 更改为 FigureCanvasTkAgg.draw_idle()