def addSeventyLine(self): global seventyLine if(seventyLine == True): seventyLine = False self.rsiGraph.setParent(None) self.candlestick.setParent(None) self.toolbar.setParent(None) self.splitter1.setParent(None) self.candlestick = mainGraphCanvas(self.main_widget) self.rsiGraph = rsiGraphCanvas(self.main_widget) self.toolbar = NavigationToolbar(self.candlestick, self.main_widget) self.splitter1 = QtGui.QSplitter(QtCore.Qt.Vertical) self.splitter1.addWidget(self.candlestick) self.splitter1.addWidget(self.rsiGraph) self.splitter1.addWidget(self.toolbar) self.graphVBox.addWidget(self.splitter1) self.rsi.show() else: seventyLine = True self.rsiGraph.setParent(None) self.candlestick.setParent(None) self.toolbar.setParent(None) self.splitter1.setParent(None) self.candlestick = mainGraphCanvas(self.main_widget) self.rsiGraph = rsiGraphCanvas(self.main_widget) self.toolbar = NavigationToolbar(self.candlestick, self.main_widget) self.splitter1 = QtGui.QSplitter(QtCore.Qt.Vertical) self.splitter1.addWidget(self.candlestick) self.splitter1.addWidget(self.rsiGraph) self.splitter1.addWidget(self.toolbar) self.graphVBox.addWidget(self.splitter1) self.rsi.show()
def __init__(self, parent=None): super(Window, self).__init__(parent) #Variables Init self.figure = plt.figure() self.ax = self.figure.add_subplot(111) canvas = FigureCanvas(self.figure) self.mat = self.ax.matshow(np.zeros((num_rows,num_cols))) #global ax, mat, ser, Array, data toolbar = NavigationToolbar(canvas, self) toolbar.hide() # Start Button self.button = QtGui.QPushButton('Start') self.button.clicked.connect(plot) #self.button1 = QtGui.QPushButton('Record') #self.button.clicked.connect(self.plot) # set the layout layout = QtGui.QVBoxLayout() layout.addWidget(canvas) layout.addWidget(self.button) self.setLayout(layout) self.figure.canvas.draw() self.timer = self.startTimer(3)
class GraphPage(QtGui.QMainWindow): def __init__(self, parent=None): super(GraphPage, self).__init__() uic.loadUi("graphPage.ui", self) self.fig_dict = {} self.listWidget.itemClicked.connect(self.changeFig) fig = Figure() self.addplot(fig) def addplot(self, fig): self.canvas = FigureCanvas(fig) self.verticalLayout.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self.widget, coordinates=True) self.verticalLayout.addWidget(self.toolbar) def rmPlot(self): self.verticalLayout.removeWidget(self.canvas) self.canvas.close() self.verticalLayout.removeWidget(self.toolbar) self.toolbar.close() def addfig(self, name, fig): self.fig_dict[name] = fig self.listWidget.addItem(name) def changeFig(self, item): text = item.text() self.rmPlot() self.addplot(self.fig_dict[text])
def __init__(self, plotCanvas, parent, custom_actions=True): """ **Properties** *_firstChange* (boolean): Whether or not the y limits of the plots were changed before. *_plot_params* (dictionary): The plot parameters given as (key, value) pare. """ NavigationToolbar2QTAgg.__init__(self, plotCanvas, parent) # properties { self._firstChange = True self._plot_params = {} # } # custom actions { if custom_actions: self.addSeparator() self.action_reset = self.addAction("Reset", self.onReset) self.action_reset.setToolTip("Reset the y limits") self.action_plus = self.addAction("+", self.onPlus) self.action_plus.setToolTip("Expand the y limits") self.action_minus = self.addAction("-", self.onMinus) self.action_minus.setToolTip("Reduce the y limits")
class Main(QMainWindow, Ui_MainWindow): def __init__(self, ): super(Main, self).__init__() self.setupUi(self) fig = Figure() self.addmpl(fig) self.rdBtn.clicked.connect(self.read) self.df = {} def read(self): try: self.df[str(self.inp.text()).split('.')[0]]=pd.read_csv(str(self.inp.text())) except IOError: print 'No such file' def clear(self): self.mplfigs.clear() self.rmmpl() def addmpl(self, fig): self.canvas = FigureCanvas(fig) self.mplvl.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self.mplwindow, coordinates=True) self.mplvl.addWidget(self.toolbar) def rmmpl(self,): self.mplvl.removeWidget(self.canvas) self.canvas.close() self.mplvl.removeWidget(self.toolbar) self.toolbar.close()
def __init__(self, canvas, parent, plot_win, prj, coordinates=True): self.plot_win = plot_win self.prj = prj self.grid_action = None self.flagged_action = None self.flag_action = None self.unflag_action = None self.insert_action = None self.insert_sample = None self.mon_label = None self._ids_flag = None self._flag_mode = None self._flag_start = None self._flag_end = None # custom cursors pan_px = QtGui.QPixmap(os.path.join(self.media, 'pan_cursor.png')) pan_px.setMask(pan_px.mask()) self.pan_cursor = QtGui.QCursor(pan_px) grab_px = QtGui.QPixmap(os.path.join(self.media, 'grab_cursor.png')) grab_px.setMask(grab_px.mask()) self.grab_cursor = QtGui.QCursor(grab_px) NavigationToolbar2QT.__init__(self, canvas=canvas, parent=parent, coordinates=coordinates) self.setIconSize(QtCore.QSize(24, 24)) self.canvas.mpl_connect('button_press_event', self.press) self.canvas.mpl_connect('button_release_event', self.release)
class Main(QMainWindow, Ui_MainWindow): def __init__(self, ): super(Main, self).__init__() self.setupUi(self) self.fig_dict = {} self.mplfigs.itemClicked.connect(self.change_fig) def change_fig(self, item): text = item.text() self.rm_mpl() self.add_mpl(self.fig_dict[text]) def add_mpl(self, fig): self.canvas = FigureCanvas(fig) self.mplvl.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self, coordinates=True) self.addToolBar(self.toolbar) def rm_mpl(self, ): self.mplvl.removeWidget(self.canvas) self.canvas.close() self.mplvl.removeWidget(self.toolbar) self.toolbar.close() def add_fig(self, name, fig): self.fig_dict[name] = fig self.mplfigs.addItem(name)
class PicoPlotter(QtGui.QDialog): def set_class_vars(self): self.script = ones self.n_show = 30 self.live_data = np.full(self.n_show, None) def __init__(self, parent): super(PicoPlotter, self).__init__() self.parent = parent self.set_class_vars() self.populate() def populate(self): self.setWindowTitle('Live plotter') self.canvas = MplCanvas() self.nav = NavigationToolbar(self.canvas, self) '''Changed nav toolbar''' self.nav.addAction('Reset optimizer', self.reset_opt) self.layout = QtGui.QGridLayout() self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addWidget(self.nav) self.layout.addWidget(self.canvas) self.setLayout(self.layout) self.canvas.ax.set_ylim((0, 5e-5)) self.canvas.ax.set_xlim((0, .04)) width = self.canvas.width() height = self.nav.height() + self.canvas.height() + 20 self.setFixedSize(width, height) def reset_opt(self): self.live_data = np.full(self.n_show, None) def live_plot(self): try: this_shot = self.script(self.parent.data) empty_data = np.where(self.live_data == None) if len(empty_data[0]) == 0: self.live_data[0:self.n_show - 1] = self.live_data[1:self.n_show] self.live_data[-1] = this_shot else: self.live_data[empty_data[0][0]] = this_shot except AttributeError: print('Not loaded') '''def ones(self): return 1 ''' def show_window(self): self.live_plot() self.canvas.ax.clear() self.canvas.ax.plot(self.live_data) # self.canvas.ax.title(np.std(self.live_data)) self.canvas.draw()
class GrapheWidget(QtGui.QFrame): u"""classe de Widget incluant graphe + barre d'outils + boutons H/Q. """ def __init__(self, classGraphe, parent=None): QtGui.QFrame.__init__(self) self.setParent(parent) self.layout = QtGui.QVBoxLayout(self) self.graphe = classGraphe(self) self.layout.addWidget(self.graphe) self.frameToolbar = QtGui.QFrame(self) self.layoutToolbar = QtGui.QHBoxLayout(self.frameToolbar) self.layout.addWidget(self.frameToolbar) self.toolbar = NavigationToolbar(self.graphe, self) self.toolbar.setFixedWidth(500) self.layoutToolbar.addWidget(self.toolbar, alignment=QtCore.Qt.AlignLeft) self.layoutToolbar.addStretch(1) self.frameToolbar.setSizePolicy(QtGui.QSizePolicy( QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.setSizePolicy(QtGui.QSizePolicy( QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))
class MatplotlibWidgetWFPot(QtGui.QGraphicsView): def __init__(self, parent = None): QtGui.QWidget.__init__(self, parent) self.canvas = MplCanvas() self.vbl = QtGui.QVBoxLayout() self.vbl.addWidget(self.canvas) self.setLayout(self.vbl) self.canvas.ax.set_title('Calculated PCB electrode potentials', fontsize=10) self.canvas.fig.patch.set_alpha(0) self.mpl_toolbar = NavigationToolbar(self.canvas, self) params = { 'legend.fontsize': 8, 'xtick.labelsize': 8, 'ytick.labelsize': 8, 'legend.handletextpad': .5, } plt.rcParams.update(params) self.mpl_toolbar.pan() def plot(self, wfPotentials, plotitems): if hasattr(wfPotentials, 'plotTime'): argX = wfPotentials.plotTime argY = wfPotentials.potentialsOut # get axis limits to not reset zoom/pan axlim = self.canvas.ax.axis() self.canvas.ax.clear() if not any(plotitems): self.canvas.draw() return if plotitems[0]: self.canvas.ax.plot(argX, argY[1,:], 'r.') self.canvas.ax.plot(argX, argY[1,:], 'r', label="2", linewidth=1.2) if plotitems[1]: self.canvas.ax.plot(argX, argY[3,:], 'b.') self.canvas.ax.plot(argX, argY[3,:], 'b', label="4", linewidth=1.2) if plotitems[2]: self.canvas.ax.plot(argX, argY[5,:], 'g.') self.canvas.ax.plot(argX, argY[5,:], 'g', label="6", linewidth=1.2) if not axlim == (0.0, 1.0, 0.0, 1.0): self.canvas.ax.axis(axlim) else: pass self.canvas.ax.grid(True) self.canvas.ax.set_title("Calculated PCB electrode potentials", fontsize=10) self.canvas.ax.set_xlabel("Time ($\mu$s)", fontsize=10) self.canvas.ax.set_ylabel("Amplitude (bits)", fontsize=10) self.canvas.ax.legend(bbox_to_anchor=(0.02, 0.99), loc=2, borderpad=None, borderaxespad=0., fontsize=8, frameon=False) # mares in potential generation self.canvas.ax.plot([wfPotentials.incplTime,wfPotentials.incplTime],[(wfPotentials.maxAmp*2+50),-50], 'k--', linewidth=1.5) self.canvas.ax.plot([wfPotentials.plotTime[-1]-wfPotentials.outcplTime, wfPotentials.plotTime[-1]-wfPotentials.outcplTime], \ [-1,wfPotentials.maxAmp*2+1], 'k--', linewidth=1.5) #self.WaveformDisplay.canvas.ax.plot([wfPotentials.incplTime+wfPotentials.decelTime,\ #wfPotentials.incplTime+wfPotentials.decelTime],[wfPotentials.maxAmp*-2-1, wfPotentials.maxAmp*2+1], 'k--', linewidth=1) self.canvas.fig.patch.set_alpha(0) self.canvas.fig.tight_layout() self.canvas.draw() else: print 'No potentials generated'
def __init__(self, canvas, parent, browser): NavigationToolbar2QT.__init__(self, canvas, parent) for c in self.findChildren(QtGui.QToolButton): #print str(c.text()) #if str(c.text()) in ('Subplots','Customize','Back','Forward','Home'): if str(c.text()) in ('Customize', 'Back', 'Forward'): c.defaultAction().setVisible(False) self.parent = parent self.browser = browser
def __init__(self, canvas, parent, coordinates=True): NavigationToolbar2QT.__init__(self, canvas, parent, coordinates) self.setIconSize(QtCore.QSize(16, 16)) self.ct = None self.mw = None self._idPress1 = None self._idPress2 = None self._idPress3 = None
def __init__(self, parent, canvas): """ Initialization """ NavigationToolbar2.__init__(self, canvas, canvas) self._myParent = parent self._navigationMode = MyNavigationToolbar.NAVIGATION_MODE_NONE return
def __init__(self, canvas, window, profile=True): self.toolitems = list(self.toolitems) self.toolitems.insert(6, ('Profile', 'Get the profile of a line in an image', os.path.join(imgutils.RESSOURCE_PATH, "profile"), 'profile')) self.toolitems.insert(7, ('Stats', 'Get statistics on a portion of an image/line', os.path.join(imgutils.RESSOURCE_PATH, "stats"), 'stats')) NavigationToolbar.__init__(self, canvas, window) self._actions['profile'].setCheckable(True) self._actions['stats'].setCheckable(True)
def __init__(self, canvas, parent, browser): NavigationToolbar2QT.__init__(self,canvas,parent) for c in self.findChildren(QtGui.QToolButton): #print str(c.text()) #if str(c.text()) in ('Subplots','Customize','Back','Forward','Home'): if str(c.text()) in ('Customize','Back','Forward'): c.defaultAction().setVisible(False) self.parent = parent self.browser = browser
class Mpl(QtGui.QWidget, Ui_Form): def __init__(self, fig_dict, name_list): super(Mpl, self).__init__() self.setupUi(self) self.fig_dict = fig_dict self.name_list = name_list self.index = 0 self.btnBack.clicked.connect(self.back) self.btnForward.clicked.connect(self.forward) self.comboBoxSelect.addItems(self.name_list) self.comboBoxSelect.setCurrentIndex(self.index) self.comboBoxSelect.activated.connect(self.select) if self.fig_dict and self.name_list: fig = self.fig_dict[self.name_list[self.index]] else: fig = Figure() self.addmpl(fig) def changefig(self, ): self.comboBoxSelect.setCurrentIndex(self.index) fig = self.fig_dict[self.name_list[self.index]] self.rmmpl() self.addmpl(fig) def addmpl(self, fig): self.canvas = FigureCanvas(fig) # self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding) self.ltMPL.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self.wgtToolbox, coordinates=True) self.ltToolbox.addWidget(self.toolbar) def rmmpl(self, ): self.ltMPL.removeWidget(self.canvas) self.canvas.close() self.ltToolbox.removeWidget(self.toolbar) self.toolbar.close() def back(self): self.index = self.index - 1 if self.index != 0 else len( self.name_list) - 1 self.changefig() def forward(self): self.index = self.index + 1 if self.index != len( self.name_list) - 1 else 0 self.changefig() def select(self): self.index = self.comboBoxSelect.currentIndex() self.changefig()
def draw(self): """ Canvas is drawn called by pan(), zoom() :return: """ NavigationToolbar2.draw(self) self._myParent.evt_view_updated() return
class MplWidgetT(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.canvas = MplCanvas() self.ntb = NavigationToolbar(self.canvas, self) self.ntb.setIconSize(QtCore.QSize(16, 16)) self.vbl = QtGui.QVBoxLayout() self.vbl.addWidget(self.canvas) self.vbl.addWidget(self.ntb) self.setLayout(self.vbl)
def _update_view(self): """ view update called by home(), back() and forward() :return: """ NavigationToolbar2._update_view(self) self._myParent.evt_view_updated() return
class MplWidgetT(QtGui.QWidget): def __init__(self, parent = None): QtGui.QWidget.__init__(self, parent) self.canvas = MplCanvas() self.ntb = NavigationToolbar(self.canvas, self) self.ntb.setIconSize(QtCore.QSize(16, 16)) self.vbl = QtGui.QVBoxLayout() self.vbl.addWidget(self.canvas) self.vbl.addWidget(self.ntb) self.setLayout(self.vbl)
def __init__(self , parent , canvas , orientation = Qt.Vertical, close_button = False) : """ A simple matplotlib navigation toolbar that can be vertical Qt.Vertical or Qt.Horizontal """ NavigationToolbar2.__init__( self, canvas,parent ) self.setOrientation(orientation) if close_button: self.addSeparator() self.actionClose = self.addAction(QIcon(':/window-close.png'), 'Close')
def __init__(self, x, y): QtGui.QDialog.__init__(self) self.setupUi(self) fig = Figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) ax.plot(x, y, 'b-') ax.grid(True) canvas = FigureCanvas(fig) nt = NavigationToolbar(canvas, self.toolbarWidget) nt.setMinimumWidth(600) self.plotLayout.addWidget(canvas) self.show()
class Mpl(QtGui.QWidget, Ui_Form): def __init__(self, fig_dict, name_list): super(Mpl, self).__init__() self.setupUi(self) self.fig_dict = fig_dict self.name_list = name_list self.index = 0 self.btnBack.clicked.connect(self.back) self.btnForward.clicked.connect(self.forward) self.comboBoxSelect.addItems(self.name_list) self.comboBoxSelect.setCurrentIndex(self.index) self.comboBoxSelect.activated.connect(self.select) if self.fig_dict and self.name_list: fig = self.fig_dict[self.name_list[self.index]] else: fig = Figure() self.addmpl(fig) def changefig(self,): self.comboBoxSelect.setCurrentIndex(self.index) fig = self.fig_dict[self.name_list[self.index]] self.rmmpl() self.addmpl(fig) def addmpl(self, fig): self.canvas = FigureCanvas(fig) # self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding) self.ltMPL.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self.wgtToolbox, coordinates=True) self.ltToolbox.addWidget(self.toolbar) def rmmpl(self,): self.ltMPL.removeWidget(self.canvas) self.canvas.close() self.ltToolbox.removeWidget(self.toolbar) self.toolbar.close() def back(self): self.index = self.index-1 if self.index!=0 else len(self.name_list)-1 self.changefig() def forward(self): self.index = self.index+1 if self.index!=len(self.name_list)-1 else 0 self.changefig() def select(self): self.index = self.comboBoxSelect.currentIndex() self.changefig()
def __init__(self, on_changed_ev, parent=None): super(ThresholdCacheWidget, self).__init__() self.on_changed_ev = on_changed_ev self.parent = parent self.histogram_figure = plt.figure() self.histogram_canvas = FigureCanvas(self.histogram_figure) self.histogram_canvas.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding) self.histogram_canvas.setMinimumSize(50, 50) self.histogram_toolbar = NavigationToolbar(self.histogram_canvas, parent) self.histogram_toolbar.coordinates = False self.histogram_toolbar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self.image_figure = plt.figure() self.image_canvas = FigureCanvas(self.image_figure) self.image_canvas.setMinimumSize(50, 50) self.image_canvas.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding) self.image_toolbar = NavigationToolbar(self.image_canvas, parent) self.image_toolbar.coordinates = False self.image_toolbar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) gs = grd.GridSpec(3, 1) self.ax_objects = self.histogram_figure.add_subplot(gs[0, 0]) self.ax_area = self.histogram_figure.add_subplot(gs[1, 0], sharex=self.ax_objects) self.ax_image = self.image_figure.add_subplot(111) layout = QtGui.QGridLayout() q1 = QtGui.QLabel("<b>Choose Threshold</b>") layout.addWidget(q1, 0, 0, 1, 1) layout.addWidget(QtGui.QLabel("Click on either graph to pick a threshold value"), 1, 0, 1, 1) layout.addWidget(self.histogram_canvas, 3, 0, 1, 1) layout.addWidget(self.histogram_toolbar, 4, 0, 1, 1) self.roiSelectorBar = ROISelectorBar(self.image_figure, self.ax_image) self.roiSelectorBar.roi_changed.connect(self.roiSelectorBar_roi_changed) self.calibrationBar = CalibrationBar(10, self.image_figure, self.ax_image) self.calibrationBar.calibration_changed.connect(self.calibrationBar_calibration_changed) q2 = QtGui.QLabel("<b>Define Region of Interest</b>") layout.addWidget(q2, 0, 1, 1, 1) layout.addWidget(self.roiSelectorBar, 1, 1, 1, 1) layout.addWidget(self.calibrationBar, 2, 1, 1, 1) layout.addWidget(self.image_canvas, 3, 1, 1, 1) layout.addWidget(self.image_toolbar, 4, 1, 1, 1) self.setLayout(layout) self.histogram_figure.canvas.mpl_connect('button_press_event', self.on_histogram_button_pressed) # self.image_figure.canvas.mpl_connect('button_press_event', self.on_image_button_pressed) self.thresholds = []
def __init__(self,canvas_,parent_): self.toolitems = ( ('Home', 'Lorem ipsum dolor sit amet', 'home', 'home'), ('Back', 'consectetuer adipiscing elit', 'back', 'back'), ('Forward', 'sed diam nonummy nibh euismod', 'forward', 'forward'), (None, None, None, None), ('Pan', 'tincidunt ut laoreet', 'move', 'pan'), ('Zoom', 'dolore magna aliquam', 'zoom_to_rect', 'zoom'), (None, None, None, None), ('Subplots', 'putamus parum claram', 'subplots', 'configure_subplots'), ('Save', 'sollemnes in futurum', 'filesave', 'save_figure'), ) NavigationToolbar.__init__(self,canvas_,parent_)
def __init__(self, canvas, parent): NavigationToolbar2QT.__init__(self, canvas, parent) self.clearButtons = [] # Search through existing buttons # next use for placement of custom button next = None for c in self.findChildren(QToolButton): if next is None: next = c # Don't want to see subplots and customize if str(c.text()) in ('Subplots', 'Customize', 'Forward', 'Back'): c.defaultAction().setVisible(False) continue
def __init__(self, canvas, parent ): NavigationToolbar2QT.__init__(self,canvas,parent) self.clearButtons=[] # Search through existing buttons # next use for placement of custom button next=None for c in self.findChildren(QToolButton): if next is None: next=c # Don't want to see subplots and customize if str(c.text()) in ('Subplots','Customize','Forward', 'Back'): c.defaultAction().setVisible(False) continue
def __init__(self, canvas_, parent_): self.toolitems = ( ('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous view', 'back', 'back'), ('Forward', 'Forward to next view', 'forward', 'forward'), (None, None, None, None), ('Pan', 'Pan axes with left mouse, zoom with right', 'move', 'pan'), ('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'), ('Subplots', 'Configure subplots', 'subplots', 'configure_subplots'), (None, None, None, None), ('Save', 'Save the figure', 'filesave', 'save_figure'), ) NavigationToolbar.__init__(self, canvas_, parent_)
def __init__(self, canvas_, parent_): override.figureoptions = None # Monkey patched to kill the figure options button on matplotlib toolbar self.toolitems = ( ('Home', 'Reset original view', 'home', 'home'), ('Save', 'Save the current image', 'filesave', 'save_figure'), (None, None, None, None), ('Back', 'Back to previous view', 'back', 'back'), ('Forward', 'Forward to next view', 'forward', 'forward'), (None, None, None, None), ('Pan', 'Pan axes with left mouse, zoom with right', 'move', 'pan'), ('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'), ) NavigationToolbar2QT.__init__(self, canvas_, parent_)
class ScanGui(*uic.loadUiType(ui_path)): def __init__(self, motor, dets, parent=None): super().__init__(parent) self.motor = motor self.dets = dets self.setupUi(self) self.fig = fig = self.figure_content() self.addCanvas(fig) def addCanvas(self, fig): self.canvas = FigureCanvas(fig) self.toolbar = NavigationToolbar(self.canvas, self.tab_2, coordinates=True) self.toolbar.setMaximumHeight(18) self.plots.addWidget(self.toolbar) self.plots.addWidget(self.canvas) self.canvas.draw() def figure_content(self): fig1 = Figure() fig1.set_facecolor(color='0.89') fig1.stale_callback = auto_redraw_factory(fig1.stale_callback) ax1f1 = fig1.add_subplot(111) ax1f1.plot(np.random.rand(5)) self.ax = ax1f1 return fig1 @property def plan(self): from bluesky.plans import subs_decorator, scan from bluesky.callbacks import LiveTable, LivePlot from bluesky.utils import first_key_heuristic lp = LivePlot(first_key_heuristic(self.dets[0]), first_key_heuristic(self.motor), fig=self.fig) @subs_decorator([LiveTable([self.motor] + self.dets), lp]) def scan_gui_plan(): yield from scan(self.dets, self.motor, self.start.value(), self.stop.value(), self.steps.value(), md={'created_by': 'GUI'}) return scan_gui_plan()
def _initToolbar(self): toolbar = NavigationToolbar(self._canvas, self.parent()) act_save = toolbar._actions['save_figure'] act_copy = QAction(getIcon('edit-copy'), 'Copy', toolbar) toolbar.insertAction(act_save, act_copy) # Signals act_save.triggered.disconnect(toolbar.save_figure) act_save.triggered.connect(self.save) act_copy.triggered.connect(self.copy) return toolbar
def __init__(self, parent, canvas, orientation=Qt.Vertical, close_button=False): """ A simple matplotlib navigation toolbar that can be vertical Qt.Vertical or Qt.Horizontal """ NavigationToolbar2.__init__(self, canvas, parent) self.setOrientation(orientation) if close_button: self.addSeparator() self.actionClose = self.addAction(QIcon(':/window-close.png'), 'Close')
def addmpl(self, fig): self.canvas = FigureCanvas(fig) self.mplvl.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self.mplwindow, coordinates=True) self.mplvl.addWidget(self.toolbar)
def __init__(self, model, graph, index, parentWidget, *args, **kwargs): super(PlotWidget, self).__init__() self.model = model self.graph = graph self.index = index self.menu = self.getContextMenu() self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.connect( self , SIGNAL("customContextMenuRequested(QPoint)") , self , SLOT("contextMenuRequested(QPoint)") ) self.canvas = CanvasWidget(self.model, self.graph, self.index) self.canvas.setParent(self) self.navToolbar = NavigationToolbar(self.canvas, self) self.hackNavigationToolbar() self.canvas.mpl_connect('pick_event',self.togglePlot) layout = QtGui.QGridLayout() layout.addWidget(self.navToolbar, 0, 0) layout.addWidget(self.canvas, 1, 0) self.setLayout(layout) self.pathToLine = defaultdict(set) self.lineToDataSource = {} self.axesRef = self.canvas.addSubplot(1, 1) self.legend = None desktop = QtGui.QApplication.desktop() self.setMinimumSize(desktop.screenGeometry().width() / 4, desktop.screenGeometry().height() / 3) self.canvas.updateSignal.connect(self.plotAllData) self.plotAllData()
def __init__(self, figure, identifier, filepath): loader = UiLoader() self.ui = loader.load('plot_window.ui', PlotWindow()) # Tell Windows how to handle our windows in the the taskbar, making pinning work properly and stuff: if os.name == 'nt': self.ui.newWindow.connect(set_win_appusermodel) self.set_window_title(identifier, filepath) # figure.tight_layout() self.figure = figure self.canvas = FigureCanvas(figure) self.navigation_toolbar = NavigationToolbar(self.canvas, self.ui) self.lock_action = self.navigation_toolbar.addAction( QtGui.QIcon(':qtutils/fugue/lock-unlock'), 'Lock axes', self.on_lock_axes_triggered) self.lock_action.setCheckable(True) self.lock_action.setToolTip('Lock axes') self.ui.verticalLayout_canvas.addWidget(self.canvas) self.ui.verticalLayout_navigation_toolbar.addWidget( self.navigation_toolbar) self.lock_axes = False self.axis_limits = None self.update_window_size() self.ui.show()
def __init__(self, parent=None): super(Window, self).__init__(parent) self.figure = plt.figure() self.canvas = FigureCanvas(self.figure) self.toolbar = NavigationToolbar(self.canvas, self) self.toolbar.hide() # Just some button self.button = QtGui.QPushButton('Plot') self.button.clicked.connect(self.plot) self.button1 = QtGui.QPushButton('Zoom') self.button1.clicked.connect(self.zoom) self.button2 = QtGui.QPushButton('Pan') self.button2.clicked.connect(self.pan) self.button3 = QtGui.QPushButton('Home') self.button3.clicked.connect(self.home) # set the layout layout = QtGui.QVBoxLayout() layout.addWidget(self.toolbar) layout.addWidget(self.canvas) layout.addWidget(self.button) layout.addWidget(self.button1) layout.addWidget(self.button2) layout.addWidget(self.button3) self.setLayout(layout)
def __init__(self, parent = None): QWidget.__init__(self, parent) self.canvas = MplCanvas() self.vbl = QVBoxLayout() self.vbl.addWidget(self.canvas) self.setLayout(self.vbl) self.canvas.ax.set_title('Series of Averages', fontsize=12) self.canvas.fig.patch.set_alpha(0) self.canvas.fig.tight_layout() self.mpl_toolbar = NavigationToolbar(self.canvas, self) self.canvas.mpl_connect('button_press_event', self.onclick) self.mpl_toolbar.pan() params = { 'xtick.labelsize': 12, 'ytick.labelsize': 12, 'figure.autolayout': True, } plt.rcParams.update(params) self.data = [] self.distmeshsurf = 1. if sys.platform == 'darwin': self.filePath = '/Users/TPSGroup/Documents/Experimental Data/Data Mike/Raw Data/2015' else: self.filePath = 'C:\\Users\\tpsgroup\\Desktop\\Documents\\Data Mike\\Raw Data\\2015' self.trace = [False, False, False, False]
def __init__(self, parent=None, autoscaleBn = False): QtGui.QWidget.__init__(self, parent) # canvas font = self.font() windowColor = str(self.palette().window().color().name()) matplotlib.rc('font', family=str(font.family()), size=.9*font.pointSize(), weight="normal") matplotlib.rc('figure', facecolor=windowColor, edgecolor=windowColor) self.fig = Figure(dpi=self.logicalDpiX()) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self) # navigation self.navigation = NavigationToolbar(self.canvas, self, coordinates=False) self.actionGroupPlotStyle = self.navigation.addAction("Split", self.toggleGroupPlotStyle) self.actionGroupPlotStyle.setCheckable(True) self.actionAutoscale = self.navigation.addAction("Auto", self.toggleAutoscale) self.actionAutoscale.setCheckable(True) self.actionAutoscale.setChecked(True) layout = QtGui.QVBoxLayout(self) layout.addWidget(self.canvas) layout.addWidget(self.navigation) # init other stuff self.xlabel = "" self._needSetupFigure = True self._needSetupLines = True self._needRescale = True self.clearPlots() self.setGropPlotStyle("combined")
class FFTPlotter(QtGui.QDialog): def __init__(self, data, ts, t): super(FFTPlotter, self).__init__() self.populate() self.show_plot(data, ts, t) def populate(self): self.canvas = MplCanvas() self.nav = NavigationToolbar(self.canvas, self) '''Changed nav toolbar''' self.layout = QtGui.QGridLayout() self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addWidget(self.nav) self.layout.addWidget(self.canvas) self.setLayout(self.layout) #self.canvas.ax.set_ylim((0, 5e-5)) #self.canvas.ax.set_xlim((0, .04)) width = self.canvas.width() height = self.nav.height() + self.canvas.height() + 20 self.setFixedSize(width, height) def show_plot(self, data, ts, t): print('hello!!') Pxx, freqs, t0 = show_fft(data, ts, t) self.setWindowTitle('FFT at time {} s'.format(t0)) self.canvas.ax.clear() self.canvas.ax.plot(freqs * 1e-6, Pxx) print(max(freqs * 1e-6)) #self.canvas.ax.set_xlim((0, 20)) self.canvas.ax.set_xlabel("Freq (MHz)") self.canvas.draw()
def pan(self, *args): """ :param args: :return: """ NavigationToolbar2.pan(self, args) if self._navigationMode == MyNavigationToolbar.NAVIGATION_MODE_PAN: # out of pan mode self._navigationMode = MyNavigationToolbar.NAVIGATION_MODE_NONE else: # into pan mode self._navigationMode = MyNavigationToolbar.NAVIGATION_MODE_PAN return
def __init__(self, figure, identifier, filepath): loader = UiLoader() self.ui = loader.load('plot_window.ui', PlotWindow()) # Tell Windows how to handle our windows in the the taskbar, making pinning work properly and stuff: if os.name == 'nt': self.ui.newWindow.connect(set_win_appusermodel) self.set_window_title(identifier, filepath) # figure.tight_layout() self.figure = figure self.canvas = FigureCanvas(figure) self.navigation_toolbar = NavigationToolbar(self.canvas, self.ui) self.lock_action = self.navigation_toolbar.addAction( QtGui.QIcon(':qtutils/fugue/lock-unlock'), 'Lock axes', self.on_lock_axes_triggered) self.lock_action.setCheckable(True) self.lock_action.setToolTip('Lock axes') self.ui.verticalLayout_canvas.addWidget(self.canvas) self.ui.verticalLayout_navigation_toolbar.addWidget(self.navigation_toolbar) self.lock_axes = False self.axis_limits = None self.update_window_size() self.ui.show()
def display(self): """ Show the plot in an interactive window. """ # Host widget for show(): app = QApplication(sys.argv) app.aboutToQuit.connect(app.deleteLater) main_frame = QWidget() # Attach canvas to host widget: canvas = FigureCanvasQTAgg(self) canvas.setParent(main_frame) # Make navigation toolbar: mpl_toolbar = NavigationToolbar2QT(self.canvas, main_frame) # Set up layout: vbox = QVBoxLayout() vbox.addWidget(mpl_toolbar) vbox.addWidget(self.canvas) # Set the layout to the host widget: main_frame.setLayout(vbox) # Set figure manager: FigureManagerQT(self.canvas, 1) # Show plot: self.show() app.exec_()
def tabbed_qt4_window(self): from PyQt4 import QtGui from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg, NavigationToolbar2QT # mpl backend can already create instance # https://stackoverflow.com/a/40031190 app = QtGui.QApplication.instance() if app is None: app = QtGui.QApplication([self.title]) self.root_window = QtGui.QTabWidget() self.root_window.setWindowTitle(self.title) for name, fig in self.figures.items(): tab = QtGui.QWidget(self.root_window) tab.canvas = FigureCanvasQTAgg(fig) vbox = QtGui.QVBoxLayout(tab) vbox.addWidget(tab.canvas) toolbar = NavigationToolbar2QT(tab.canvas, tab) vbox.addWidget(toolbar) tab.setLayout(vbox) for axes in fig.get_axes(): if isinstance(axes, Axes3D): # must explicitly allow mouse dragging for 3D plots axes.mouse_init() self.root_window.addTab(tab, name) self.root_window.show() app.exec_()
def addplot(self, fig): #plt.savefig('common_labels_text.png', dpi=300) self.canvas = FigureCanvas(fig) self.mplvl.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self, coordinates=True) self.addToolBar(self.toolbar)
def add_mpl(self, fig): self.canvas = FigureCanvas(fig) self.mplvl.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self, coordinates=True) self.addToolBar(self.toolbar)
def openMainFig(self): if self.THEimage.any() == True: self.rmmpl() self.THEimage = np.array([]) self.BLUEimage = 0 for i in range(len(self.THEblobs)): self.table.removeRow(0) self.nMarkedCells.setText(str(0)) self.THEblobs = np.array([]) name = QtGui.QFileDialog.getOpenFileName( self, 'Single File', '~/Desktop/', "Image files (*.jpg *.png *.tif)") image = misc.imread(str(name)) self.saveNames.setText(str(name).split("/")[-1][:-4] + 'i') self.THEimage = image self.BLUEimage = image[:, :, 2] baseimage = self.fig.add_subplot(111) baseimage.axis('off') baseimage.grid(False) baseimage.imshow(image) self.canvas = FigureCanvas(self.fig) self.mplvl.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self.widget, coordinates=True) self.mplvl.addWidget(self.toolbar) cid = self.fig.canvas.mpl_connect('button_press_event', self.onclick)
def _createPlotWidget(self): self._plotWidget = QWidget() self._plotFigure = Figure() self._plotCanvas = FigureCanvas(self._plotFigure) self._plotCanvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._plotCanvas.updateGeometry() self._plotCanvas.setParent(self._plotWidget) self._plotCanvas.mpl_connect('scroll_event', self._onScroll) self._plotFigure.set_canvas(self._plotCanvas) # Vm and command voltage go in the same subplot self._vm_axes = self._plotFigure.add_subplot(2,2,1, title='Membrane potential') self._vm_axes.set_ylim(-20.0, 120.0) # Channel conductances go to the same subplot self._g_axes = self._plotFigure.add_subplot(2,2,2, title='Channel conductance') self._g_axes.set_ylim(0.0, 0.5) # Injection current for Vclamp/Iclamp go to the same subplot self._im_axes = self._plotFigure.add_subplot(2,2,3, title='Injection current') self._im_axes.set_ylim(-0.5, 0.5) # Channel currents go to the same subplot self._i_axes = self._plotFigure.add_subplot(2,2,4, title='Channel current') self._i_axes.set_ylim(-10, 10) for axis in self._plotFigure.axes: axis.set_autoscale_on(False) layout = QVBoxLayout() layout.addWidget(self._plotCanvas) self._plotNavigator = NavigationToolbar(self._plotCanvas, self._plotWidget) layout.addWidget(self._plotNavigator) self._plotWidget.setLayout(layout)
def populate(self): self.setWindowTitle(self.channel) self.canvas = MplCanvas() self.nav = NavigationToolbar(self.canvas, self) self.ramp_table = RampTable(self.ramp_maker) self.ramp_scroll = QtGui.QScrollArea() self.buttons = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self) self.ramp_scroll.setWidget(self.ramp_table) self.ramp_scroll.setFixedHeight( self.ramp_table.height() + self.ramp_scroll.horizontalScrollBar().height() - 10) self.ramp_scroll.setWidgetResizable(True) self.buttons.button(QtGui.QDialogButtonBox.Ok).setDefault(False) self.layout = QtGui.QGridLayout() self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addWidget(self.nav) self.layout.addWidget(self.canvas) self.layout.addWidget(self.ramp_scroll) self.layout.addWidget(self.buttons) self.setLayout(self.layout) width = self.canvas.width() height = self.nav.height() + self.canvas.height( ) + self.ramp_scroll.height() + 20 self.setFixedSize(width, height) yield self.set_columns() yield self.replot()
def add_fftmpl(self, fig): self.fft_canvas = FigureCanvas(fig) self.vl_fft.addWidget(self.fft_canvas) self.fft_canvas.draw() self.fft_toolbar = NavigationToolbar(self.fft_canvas, self, coordinates=True) self.vl_fft.addWidget(self.fft_toolbar)
def __init__(self, main, ind, dep, color): QDialog.__init__(self, main) self.main = main self.setPalette(main.palette()) self.ind = ind self.dep = dep self.color = color self.info = QLabel('Click on a point to highlight the corresponding' ' record') self.figure = mpl.figure.Figure() self.canvas = FigureCanvasQTAgg(self.figure) self.canvas.setParent(self) self.canvas.setFocus() self.toolbar = NavigationToolbar2QT(self.canvas, self) self.ax = self.figure.add_subplot(111) self.scatterPlot = self.ax.scatter(self.ind, self.dep, c=self.color, picker=5, cmap=mpl.cm.YlGnBu_r) if self.color is not None: self.colorbar = self.figure.colorbar(self.scatterPlot) self.canvas.mpl_connect('pick_event', self.main.handleClick) vbox = QVBoxLayout() vbox.addWidget(self.info) vbox.addWidget(self.canvas) vbox.addWidget(self.toolbar) self.setLayout(vbox) self.show()
def zoom(self, *args): """ Turn on/off zoom (zoom button) :param args: :return: """ NavigationToolbar2.zoom(self, args) if self._navigationMode == MyNavigationToolbar.NAVIGATION_MODE_ZOOM: # out of zoom mode self._navigationMode = MyNavigationToolbar.NAVIGATION_MODE_NONE else: # into zoom mode self._navigationMode = MyNavigationToolbar.NAVIGATION_MODE_ZOOM return
def __init__(self, canvas, parent ): NavigationToolbar2QT.__init__(self,canvas,parent) self.clearButtons=[] # Search through existing buttons # next use for placement of custom button next=None for c in self.findChildren(QtGui.QToolButton): if next is None: next=c # Don't want to see subplots and customize """ if str(c.text()) in ('Subplots', 'Customize'): c.defaultAction().setVisible(False) continue """ # Need to keep track of pan and zoom buttons # Also grab toggled event to clear checked status of picker button if str(c.text()) in ('Pan','Zoom'): c.toggled.connect(self.clearCurs) self.clearButtons.append(c) next=None # create custom button pm=QtGui.QPixmap(32,32) pm.fill(QtGui.QApplication.palette().color(QtGui.QPalette.Normal,QtGui.QPalette.Button)) painter=QtGui.QPainter(pm) painter.fillRect(6,6,20,20,QtCore.Qt.red) painter.fillRect(15,3,3,26,QtCore.Qt.blue) painter.fillRect(3,15,26,3,QtCore.Qt.blue) painter.end() icon=QtGui.QIcon(pm) ac = self.addAction(icon, "Toggle Curs") ac.setCheckable(True) ac.toggled.connect(self.curs_toggle) self.ac = ac #button=QtGui.QToolButton(self) #button.setDefaultAction(self.ac) # Add it to the toolbar, and connect up event #self.insertWidget(next.defaultAction(),button) # Grab the picked event from the canvas canvas.mpl_connect('pick_event',self.canvasPicked)
def update_page_6(self, fig): self.clear_page_6() logging.debug('Update page 6: phn2') self.canvas_6 = FigureCanvas(fig) self.phn2.addWidget(self.canvas_6) self.canvas_6.draw() self.toolbar_6 = NavigationToolbar(self.canvas_6, self.phn2_page, coordinates=True) self.phn2.addWidget(self.toolbar_6)
def update_page_7(self, fig): self.clear_page_7() logging.debug('Clear page 7: 3d-covmat') self.canvas_7 = FigureCanvas(fig) self.covmat_field.addWidget(self.canvas_7) self.canvas_7.draw() self.toolbar_7 = NavigationToolbar(self.canvas_7, self.tab_covmat, coordinates=True) self.covmat_field.addWidget(self.toolbar_7)