how to modify a loaded pickled figure in Matplotlib?

27 views Asked by At

I'm able to dump/save and open/load. the figure is loaded with all the previously plotted Line2D objects. however, this figure is unchangeable: can't add subplot, can't add or remove a line, can't add mplcursor... it seems the callbacks are not properly registered. is this even possible?

class MatplotlibWidget(QWidget):
    def __init__(self, parent=None):
        super(MatplotlibWidget, self).__init__(parent)
        self.figure = plt.figure(tight_layout=True)
        self.canvas = Canvas(self.figure)
        self.axe = self.canvas.figure.subplots()

    def pickle_dump(self):
        saveFile = QFileDialog.getSaveFileName(self, "Save file", "", "file (*.*)")[0]
        with open(saveFile, "wb") as f:
            pickle.dump(self.figure, f)
            pickle.dump(self.canvas.figure, f)
        f.close()

    def pickle_load(self):
        lodFile = QFileDialog.getOpenFileName(self, "Open file", "", "file (*.*)")[0]
        with open(lodFile, "rb") as f:
            self.figure = pickle.load(f)
            self.canvas.figure = pickle.load(f)
        self.canvas.draw()



0

There are 0 answers