I'm a python beginner, and I'm developing my first GUI using QtDesigner to draw serial port reads to HF data.
I have added four widgets to it. I'm using matplotlib.animation class, but I found that if I start four plots at the same time, the GUI becomes much less responsive, I think it's because of the large amount of data to draw, because if I start four plots at the same time, I have to draw a total of 3600 data points, and I'm using canvas.draw(), the coordinates of each time will also be will be redrawn each time.
I tried to use blitting to speed up the drawing now, but it didn't work.
Here is a plotting program, maybe you can help me, I would be very grateful!
def start_animation_2(self):
if self.freeze_plot2:
# self.ani3.pause()
self.ani2.event_source.stop()
else:
self.ani2 = FuncAnimation(
self.view.MplWidget2,
self.update_view2,
interval=300,
cache_frame_data=False,
blit=True,
)
self.view.MplWidget2.canvas.draw()
def update_view2(self, frame_data=None):
package_info = self.get_package_info()
self.subrecord_data = self.notify_new_data()
ax = self.view.MplWidget2.canvas.axes
unit = constants.Units.get(package_info[4][1], "")
ax.clear()
ax.grid(True)
line = ax.plot(self.subrecord_data[1][-900:])
ax.set_xlabel("Data points")
ax.set_ylabel(f"{package_info[4][1]} ({unit})")
return (line,)
class MplWidget2(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.canvas = FigureCanvas(Figure())
vertical_layout = QVBoxLayout()
vertical_layout.addWidget(self.canvas)
self.canvas.axes = self.canvas.figure.add_subplot(111)
self.canvas.axes.grid(True)
self.canvas.figure.set_size_inches(8, 6)
self.canvas.figure.subplots_adjust(
left=0.075, right=0.95, bottom=0.19, top=0.95
)
self.setLayout(vertical_layout)