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
- 这是我的程序功能的简要总结:
- 我有一个 class 实现了 tkinter window;在构造函数中,我实例化了以下绘图变量:
self.figure = Figure(figsize=(5, 5), dpi=100)
self.subplot = self.figure.add_subplot(111)
self.canvas = FigureCanvasTkAgg(
self.figure, master=self.tkWindow)
- 然后,class有这个方法来更新情节:
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
我的树莓派上的版本:
- Ubuntu 20.04.3
- Python3 3.8.10
- Matplotlib 3.3.4
- Tkinter 0.1.0
我的 Raspberry Pi 3 B+ 和 Raspbian 运行 也遇到了同样的问题。
尝试将 FigureCanvasTkAgg.draw()
更改为 FigureCanvasTkAgg.draw_idle()
我在 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
- 这是我的程序功能的简要总结:
- 我有一个 class 实现了 tkinter window;在构造函数中,我实例化了以下绘图变量:
self.figure = Figure(figsize=(5, 5), dpi=100)
self.subplot = self.figure.add_subplot(111)
self.canvas = FigureCanvasTkAgg(
self.figure, master=self.tkWindow)
- 然后,class有这个方法来更新情节:
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
我的树莓派上的版本:
- Ubuntu 20.04.3
- Python3 3.8.10
- Matplotlib 3.3.4
- Tkinter 0.1.0
我的 Raspberry Pi 3 B+ 和 Raspbian 运行 也遇到了同样的问题。
尝试将 FigureCanvasTkAgg.draw()
更改为 FigureCanvasTkAgg.draw_idle()