def __init__(self): super(MPLplot, self).__init__() self.figure = plt.Figure() self.canvas = bkend.FigureCanvasQTAgg(self.figure) self.toolbar = bkend.NavigationToolbar2QT(self.canvas, self) self.ax = self.figure.add_subplot(111) layout = QVBoxLayout() layout.addWidget(self.toolbar) layout.addWidget(self.canvas) self.setLayout(layout)
def createMplInterface(self, tab): """Create mpl interface as grid of figure and navigation toolbar.""" fig = plt.figure(dpi=self.dpi) canvas = backend_qt5agg.FigureCanvasQTAgg(fig) canvas.mpl_connect("resize_event", self.tightLayout) toolbar = backend_qt5agg.NavigationToolbar2QT(canvas, self) grid = QtWidgets.QGridLayout() tab.setLayout(grid) grid.addWidget(toolbar, 0, 0) grid.addWidget(canvas, 1, 0) return fig, canvas
def initializeFigure(self): self.figure = Figure() self.axis, self.timelineAxis = self.figure.subplots(2,1, gridspec_kw={'height_ratios': [8, 1]}) self.figure.set_tight_layout(True) self.figureCanvas = pltQt5.FigureCanvas(self.figure) self.layout.addWidget(self.figureCanvas) self.plotToolBar = pltQt5.NavigationToolbar2QT(self.figureCanvas, self) self.figure.canvas.mpl_connect('button_press_event', self.onClick)
def buildUI(self): self.centralwidget = QtWidgets.QWidget(self) self.centralwidget.setObjectName("centralwidget") self.myQVBoxLayout = QtWidgets.QVBoxLayout(self.centralwidget) # # toolbar self.toolbarWidget = myToolbarWidget() self.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolbarWidget) # # tree view of files self.myTableWidget = QtWidgets.QTreeWidget() # append to layout self.myQVBoxLayout.addWidget(self.myTableWidget) # # dv/dt plot self.myGraphicsView = myQGraphicsView( plotThis='dvdt') #myQGraphicsView(self.centralwidget) self.myQVBoxLayout.addWidget(self.myGraphicsView) # # vm plot self.myGraphicsView = myQGraphicsView( plotThis='vm') #myQGraphicsView(self.centralwidget) self.myQVBoxLayout.addWidget(self.myGraphicsView) # # stat plot static_canvas = backend_qt5agg.FigureCanvas( mpl.figure.Figure(figsize=(5, 3))) self.myQVBoxLayout.addWidget(static_canvas) # i want the mpl toolbar in the mpl canvas or sublot # this is adding mpl toolbar to main window -->> not what I want #self.addToolBar(backend_qt5agg.NavigationToolbar2QT(static_canvas, self)) # this kinda works as wanted, toolbar is inside mpl plot but it is F*****G UGLY !!!! self.mplToolbar = backend_qt5agg.NavigationToolbar2QT( static_canvas, static_canvas) self._static_ax = static_canvas.figure.subplots() t = np.linspace(0, 10, 501) self._static_ax.plot(t, np.tan(t), ".") # # leave here, critical self.setCentralWidget(self.centralwidget)
def __init__(self, name, image, feature, alpha=0.5): super(Visualizer, self).__init__() self.name = name self.image = image self.feature = feature self.draw_feature = utils.visualize.DrawFeature(alpha) layout = QtWidgets.QVBoxLayout(self) fig = plt.Figure() self.ax = fig.gca() self.canvas = qtagg.FigureCanvasQTAgg(fig) layout.addWidget(self.canvas) toolbar = qtagg.NavigationToolbar2QT(self.canvas, self) layout.addWidget(toolbar) self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self) self.slider.setRange(0, feature.shape[0] - 1) layout.addWidget(self.slider) self.slider.valueChanged[int].connect(self.on_progress) self.ax.imshow(self.image) self.ax.set_xticks([]) self.ax.set_yticks([]) self.on_progress(0)
def widgetsSetup(self): # 左侧按钮 self.FileInputButton = QtWidgets.QPushButton(self) self.FileInputButton.setObjectName('AudiInput') self.FileInputButton.setText('Input File') self.FileInputButton.clicked.connect(self.slot_button_fileinput) self.SpecTransformButton = QtWidgets.QPushButton(self) self.SpecTransformButton.setObjectName('SpecTransform') self.SpecTransformButton.setText('Spec Transformation') self.SpecTransformButton.clicked.connect( self.slot_button_spectransform) self.ModelPredictButton = QtWidgets.QPushButton(self) self.ModelPredictButton.setObjectName('ModelPredict') self.ModelPredictButton.setText('Model Predictor') self.ModelPredictButton.clicked.connect(self.slot_button_modelpredict) self.MidiPlayerButton = QtWidgets.QPushButton(self) self.MidiPlayerButton.setObjectName('MidiPlayer') self.MidiPlayerButton.setText('MIDI Player') self.MidiPlayerButton.clicked.connect(self.slot_button_midiplayer) self.MidiOutputButton = QtWidgets.QPushButton(self) self.MidiOutputButton.setObjectName('MidiOutput') self.MidiOutputButton.setText('Output MIDI') self.MidiOutputButton.clicked.connect(self.slot_button_midioutput) self.CloseFileButton = QtWidgets.QPushButton(self) self.CloseFileButton.setObjectName('CloseFile') self.CloseFileButton.setText('Close File') self.CloseFileButton.clicked.connect(self.slot_button_closefile) self.AboutButton = QtWidgets.QPushButton(self) self.AboutButton.setObjectName('About') self.AboutButton.setText('About') self.AboutButton.clicked.connect(self.slot_button_about) # 右侧图表 # 参考: https://blog.csdn.net/qq_40587575/article/details/85171401, # 参考: https://www.geeksforgeeks.org/how-to-embed-matplotlib-graph-in-pyqt5/ self.SpecDiagramFigure = plt.figure(figsize=(3, 2), dpi=100) self.SpecDiagramFigure.suptitle('Spectrogram Transformation') self.SpecDiagramCanvas = matplotlib_qt5agg.FigureCanvasQTAgg( self.SpecDiagramFigure) self.SpecDiagramToolbar = matplotlib_qt5agg.NavigationToolbar2QT( self.SpecDiagramCanvas, self) self.PredDiagramFigure = plt.figure(figsize=(3, 2), dpi=100) self.PredDiagramFigure.suptitle('Piano-roll Prediction') self.PredDiagramCanvas = matplotlib_qt5agg.FigureCanvasQTAgg( self.PredDiagramFigure) self.PredDiagramToolbar = matplotlib_qt5agg.NavigationToolbar2QT( self.PredDiagramCanvas, self) # 右侧按钮 self.SpecLeftButton = QtWidgets.QPushButton(self) self.SpecLeftButton.setObjectName('SpecLeft') self.SpecLeftButton.setText('<') self.SpecLeftButton.clicked.connect(self.slot_button_specleft) self.SpecRightButton = QtWidgets.QPushButton(self) self.SpecRightButton.setObjectName('SpecRight') self.SpecRightButton.setText('>') self.SpecRightButton.clicked.connect(self.slot_button_specright) self.PredLeftButton = QtWidgets.QPushButton(self) self.PredLeftButton.setObjectName('PredLeft') self.PredLeftButton.setText('<') self.PredLeftButton.clicked.connect(self.slot_button_predleft) self.PredRightButton = QtWidgets.QPushButton(self) self.PredRightButton.setObjectName('PredRight') self.PredRightButton.setText('>') self.PredRightButton.clicked.connect(self.slot_button_predright) # 右侧文本 self.SpecOffsetLabel = QtWidgets.QLabel(self) self.SpecOffsetLabel.setObjectName('SpecOffset') self.SpecOffsetLabel.setText('?/?') self.SpecOffsetLabel.setAlignment(QtCore.Qt.AlignCenter) self.PredOffsetLabel = QtWidgets.QLabel(self) self.PredOffsetLabel.setObjectName('PredOffset') self.PredOffsetLabel.setText('?/?') self.PredOffsetLabel.setAlignment(QtCore.Qt.AlignCenter) # 利用信号和槽实现初始化 self.buttonLock.emit(False) self.buttonLock.emit(True)
def buildUI(self): self.centralwidget = QtWidgets.QWidget(self) self.centralwidget.setObjectName("centralwidget") self.myQVBoxLayout = QtWidgets.QVBoxLayout(self.centralwidget) # # toolbar ''' print('buildUI() building toobar') self.toolbarWidget = myToolbarWidget() self.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolbarWidget) ''' # # tree view of files print('buildUI() building file tree') #self.myTableWidget = QtWidgets.QTreeWidget() self.myTableWidget = QtWidgets.QTableWidget() self.myTableWidget.setRowCount(10) self.myTableWidget.setColumnCount(10) self.myTableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.myTableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.myTableWidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection) self.myTableWidget.cellClicked.connect(self.on_table_click) headerLabels = ['a ' + str(x) for x in range(10)] self.myTableWidget.setHorizontalHeaderLabels(headerLabels) for i in range(10): for j in range(10): item = QtWidgets.QTableWidgetItem('aaaaaaaaaaaaaaaaa ' + str(i*j)) self.myTableWidget.setItem(i,j, item) # append to layout self.myQVBoxLayout.addWidget(self.myTableWidget) # # # detect/plot widget # # self.myDetectionWidget = bDetectionWidget(ba) # add the detection widget to the main vertical layout self.myQVBoxLayout.addWidget(self.myDetectionWidget) # # # stat plot # # #self.myHBoxLayout_statplot = QtWidgets.QHBoxLayout(self.centralwidget) self.myHBoxLayout_statplot = QtWidgets.QHBoxLayout() plotToolbarWidget = myStatPlotToolbarWidget() self.myHBoxLayout_statplot.addWidget(plotToolbarWidget)#, stretch=2) # stretch=10, not sure on the units??? print('buildUI() building matplotlib x/y plot') #static_canvas = backend_qt5agg.FigureCanvas(mpl.figure.Figure(figsize=(5, 3))) static_canvas = backend_qt5agg.FigureCanvas(mpl.figure.Figure()) self._static_ax = static_canvas.figure.subplots() xPlot, yPlot = ba.getStat('peakSec', 'peakVal') self._static_ax.plot(xPlot, yPlot, ".") # i want the mpl toolbar in the mpl canvas or sublot # this is adding mpl toolbar to main window -->> not what I want #self.addToolBar(backend_qt5agg.NavigationToolbar2QT(static_canvas, self)) # this kinda works as wanted, toolbar is inside mpl plot but it is F*****G UGLY !!!! self.mplToolbar = backend_qt5agg.NavigationToolbar2QT(static_canvas, static_canvas) # params are (canvas, parent) self.myHBoxLayout_statplot.addWidget(static_canvas) #, stretch=8) # stretch=10, not sure on the units??? #self.myQVBoxLayout.addWidget(static_canvas) self.myQVBoxLayout.addLayout(self.myHBoxLayout_statplot) # # leave here, critical self.setCentralWidget(self.centralwidget) print('buildUI() done')