Optimizing PyQt5 and Matplotlib canvas redrawing for real-time data processing, was originally closed as Needs more focus, deleted by the OP, opened as a new, subsequently deleted question, migrated back to the original post, and reopened.
The question is, should this question remain closed?
My original, now deleted comment, was something like:
My scripts does the job, but I wanna increase the speed of it. Please review What topics can I ask about here? & Don't advise on off-topic questions. The question is asking for opinions, and lacks focus.
The reasoning was, the issues raised in the question can't be reproduced because this is regarding a GUI for real time data processing, using a webcam, and only provides:
class Canvas(FigureCanvas):
def __init__(self, parent=None):
fig, (self.ax1, self.ax2) = plt.subplots(2, sharex= True, sharey= False, figsize=(10, 10))
super(Canvas, self).__init__(fig)
and part of the while
cycle
self.canvas.ax1.cla()
self.canvas.ax2.cla()
self.canvas.ax1.plot(self.dn, self.dx, label = 'X tengely', linewidth = 1, color='#66ff33')
self.canvas.ax2.plot(self.dn, self.dy, label = 'Y tengely', linewidth = 1, color='#ff5050')
self.canvas.ax1.legend('X')
self.canvas.ax2.legend('Y')
self.canvas.ax1.set_xlim(i - 50, i)
self.canvas.ax2.set_xlim(i - 50, i)
self.canvas.draw()
The question does include examples of attempted fixes. However, since there is not enough code, and required hardware, for contributors to actually run, the question doesn't have enough focus, needs debugging details, and seeks opinions.
Is it okay to ask for code optimization help? suggests information, such as profiling, to also include in the question.
The assertion about opinions is because a question that can't be reproduced, is likely to result in answers with opinions, and guessing.
As proof of the point, this posted answer, offers opinions like Essentially, matplotlib's architecture is not suitable for what you're trying to do, and suggests an alternate package. Nothing concrete for the OP. Incidentally, questions Seeking recommendations for books, tools, software libraries, and more should be closed.
The assertion about focus is because there isn't enough focus on the specific detail of the slowdown, which could be informed by profiling output, and because the metric is ambiguous:
I would like to make a faster solution, because now the
canvas.draw()
method seems a little slow for me,...
Clear Question & Complete Minimal Reproducible Code
How do you real-time plot a colormap? was just posted (2023-06-06 19:18:26) by a new, low rep user, and is an excellent example of a clear question, with a complete, executable, minimal reproducible example for QT and real-time visualizations.
I was able to copy the code as posted, and run it in PyCharm.