def __init__(self, parent=None): """Add figure canvas to layout.""" super().__init__(parent) self.figure = _Figure() self.canvas = _FigureCanvas(self.figure) self.ax = self.figure.add_subplot(111) _layout = QtWidgets.QVBoxLayout() _layout.addWidget(self.canvas) self.toolbar = _Toolbar(self.canvas, self) _layout.addWidget(self.toolbar) self.setLayout(_layout)
self.fig = None self.ax = None self.img = None self.canvas = None self.toolbar = None app = _QApplication(_sys.argv) winTest = testWindow() winTest.ui.mpl = _winMpl() winTest.ui.mpl.fig = _Figure() winTest.ui.mpl.ax = winTest.ui.mpl.fig.add_subplot(111) data = _np.random.rand(20, 20, 50) data_slice = data[:, :, 25] winTest.ui.mpl.img = winTest.ui.mpl.ax.imshow(data_slice, interpolation='none', cmap=_mpl.cm.gray, origin='lower') winTest.ui.mpl.canvas = _FigureCanvas(winTest.ui.mpl.fig) winTest.ui.verticalLayout.insertWidget(0, winTest.ui.mpl.canvas) winTest.ui.pushbutton.pressed.connect(buttonPress) winTest.show() selectiondata = ImageSelection() _sys.exit(app.exec_())
def __init__(self, data, x=None, plugin=None, xlabel=None, ylabel=None, show_difference=False, parent=None): super(DialogPlotEffect, self).__init__(parent) self.ui = Ui_DialogPlotEffect() self.ui.setupUi(self) self.data = data self.mpl_orig = _winMpl() self.mpl_orig.fig = _Figure(facecolor=[1, 1, 1]) self.mpl_orig.ax = self.mpl_orig.fig.add_subplot(111) self.mpl_orig.canvas = _FigureCanvas(self.mpl_orig.fig) self.mpl_orig.toolbar = _NavigationToolbar(self.mpl_orig.canvas, None) self.mpl_affected = _winMpl() self.mpl_affected.fig = _Figure(facecolor=[1, 1, 1]) self.mpl_affected.ax = self.mpl_affected.fig.add_subplot(111) self.mpl_affected.canvas = _FigureCanvas(self.mpl_affected.fig) self.mpl_affected.toolbar = _NavigationToolbar( self.mpl_affected.canvas, None) self.ui.verticalLayout.insertWidget(1, self.mpl_orig.canvas) self.ui.verticalLayout.insertWidget(1, self.mpl_orig.toolbar) self.ui.verticalLayout.insertWidget(3, self.mpl_affected.canvas) self.ui.verticalLayout.insertWidget(3, self.mpl_affected.toolbar) # Plugin that brings functionality to PlotEffect self.plugin = plugin # Signal emited when something changes in the plugin widget self.plugin.changed.connect(self.widget_changed) if xlabel is None: self.ui.xlabel = self.XLABEL else: self.ui.xlabel = xlabel if ylabel is None: self.ui.ylabel = self.YLABEL else: self.ui.ylabel = ylabel if x is None: self.x = _np.linspace(0, data.shape[0], self.data.shape[0]) else: self.x = x self.show_diff = show_difference if not isinstance(data, list): try: self.mpl_orig.ax.plot(self.x, data) except: self.mpl_orig.ax.plot(self.x, data.T) self.mpl_orig.ax.xaxis.set_label_text(self.ui.xlabel) self.mpl_orig.ax.yaxis.set_label_text(self.ui.ylabel) # self.mpl_orig.fig.tight_layout(rect=[-.05,0.05,1,.95]) self.mpl_orig.ax.set_title('Original') else: if self.plugin is not None: try: self.mpl_orig.ax.plot(self.x, self.plugin.fcn(self.data)) except: self.mpl_orig.ax.plot(self.x, self.plugin.fcn(self.data).T) self.mpl_orig.ax.xaxis.set_label_text(self.ui.xlabel) self.mpl_orig.ax.yaxis.set_label_text(self.ui.ylabel) # self.mpl_orig.fig.tight_layout(rect=[0,0.05,1,.9]) self.mpl_orig.ax.set_title('Original') if self.plugin is not None: self.ui.verticalLayout.insertWidget(8, plugin) self.widget_changed() self.mpl_orig.canvas.draw() self.mpl_affected.canvas.draw() self.ui.pushButtonOk.clicked.connect(self.accept) self.ui.pushButtonCancel.clicked.connect(self.reject)
class _winMpl: def __init__(self): self.fig = None self.ax = None self.img = None self.canvas = None self.toolbar = None app = _QApplication(_sys.argv) winTest = testWindow() winTest.ui.mpl = _winMpl() winTest.ui.mpl.fig = _Figure() winTest.ui.mpl.ax = winTest.ui.mpl.fig.add_subplot(111) data = _np.random.rand(20,20,50) data_slice = data[:,:,25] winTest.ui.mpl.img = winTest.ui.mpl.ax.imshow(data_slice, interpolation='none', cmap = _mpl.cm.gray , origin='lower') winTest.ui.mpl.canvas = _FigureCanvas(winTest.ui.mpl.fig) winTest.ui.verticalLayout.insertWidget(0,winTest.ui.mpl.canvas) winTest.ui.pushbutton.pressed.connect(buttonPress) winTest.show() selectiondata = ImageSelection() _sys.exit(app.exec_())