Issue
I'm using matplotlib inside a tkinter window on python3. The program works fine on my coding machine (ubuntu18.04 running in windows WSL). Unfortunately, I need this program to run on my Raspberry Pi 4 which has Ubuntu20.04 64bit installed with the distro Ubuntu Mate 1.24.0. When I run my program on the RPi I get segmentation fault as soon as I call
FigureCanvasTkAgg.draw()
Nevertheless, I use matplotlib in other programs (using pyplot) and they work fine.
Details:
- these are my imports:
import tkinter as tk
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
- This is a brief summary of what my program does:
- I have a class that implements the tkinter window; in the constructor, I instantiate the following plot variables:
self.figure = Figure(figsize=(5, 5), dpi=100)
self.subplot = self.figure.add_subplot(111)
self.canvas = FigureCanvasTkAgg(
self.figure, master=self.tkWindow)
- Then, the class has this method to update the plot:
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)
Versions on my windows machine:
- Ubuntu 18.04.5
- Python3 3.6.9
- Matplotlib 2.1.1
- Tkinter 0.1.0
Versions on my RPi:
- Ubuntu 20.04.3
- Python3 3.8.10
- Matplotlib 3.3.4
- Tkinter 0.1.0
Solution
I've had the same problem on my Raspberry Pi 3 B+ with Raspbian running on it.
Try changing FigureCanvasTkAgg.draw()
with FigureCanvasTkAgg.draw_idle()
Answered By - Clown Down
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.