'How tracking curve parameter changes via the toolbar?

I have a GUI application written in qt (pyside2) that has realtime plotting using matplotlib. Is there any way to track changes in curve parameters via matplotlib toolbar

pic

e.g. a new curve color to use it somewhere in the program later? For example, through signal/slot mechanism like in qt?

A minimal code example for running matplotlib inside qt (pyside2)

import sys

from PySide2.QtWidgets import *

import numpy as np

import matplotlib
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT
from matplotlib.figure import Figure
matplotlib.use('Qt5Agg')


class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)

        self.widget = QWidget()
        self.fig = Figure()
        self.canvas = FigureCanvasQTAgg(self.fig)
        self.toolbar = NavigationToolbar2QT(self.canvas, self)

        vbox = QVBoxLayout()
        vbox.addWidget(self.toolbar)
        vbox.addWidget(self.canvas)  # the matplotlib canvas
        self.widget.setLayout(vbox)
        self.setCentralWidget(self.widget)

        self.axes = self.fig.add_subplot(111)
        X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
        C, S = np.cos(X), np.sin(X)

        self.axes.plot(X, C,  linewidth=1.0, linestyle="-", label="cos")

        self.axes.plot(X, S,  linewidth=1.0, linestyle="-", label="sin")
        self.axes.legend()
        self.canvas.draw()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source