I am working on a big dataframe where each row includes the values of various signals and all the rows should visualize based on their signals. Controlling this process on the single core takes a huge amount of time. Therefore I wanted to split the dataset into multiple cores for accelerating the plotting process.
I have a class that is inherited from FigureCanvasBase and includes a matplotlib figure. Objects from this class are generated from multiple different processes and then added to the layout for shown in pyqt5-based GUI. It was working when I inherited it from FigureCanvas but due to using multiprocess, I can use FigureCanvasBase but not FigureCanvas anymore.
class Canvas(FigureCanvasBase):
def __init__(self, x, y):
fig = Figure(figsize=(5, 3))
super().__init__(fig)
self.figure = fig
ax = self.figure.subplots()
for key in y.keys():
ax.plot(x, [abs(number) for number in y[key]])
self.figure.tight_layout()
def generate_class_func(list_of_dfs, x, y):
list_of_custom_classes = list()
for df in list_of_dfs:
canvas = Canvas(df, x, y)
list_of_custom_classes.append(canvas)
return list_of_custom_classes
import multiprocess as mp
with mp.Pool() as p:
from itertools import repeat
list_of_classes_list = p.starmap(generate_class_func, [[0,{a:1}],[2,{b:3}],[4,{c:5}],[6,{d:7}]])
p.close()
p.join()
canvas = Canvas([1,2], [a:3,b:4])
layout = QHBoxLayout()
layout.addWidget(canvas)
>>> {TypeError}addWidget(self, QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = 0): argument 1 has unexpected type 'Canvas'
Any recommendations for adding Canvas objects to layouts?