def repeatplot(self, *args): table = open("%sstate_table" % config.path_states, "r") lines = table.readlines() x = [] y = [] unsortedlines = [] sortedlines = [] grouplabels = [] for i in range(2, len(lines)): x.append(i - 2) unsortedlines.append((lines[i].split()[0], lines[i].split()[2])) sortedlines = sorted(unsortedlines, key=lambda tuble: int(tuble[1])) for i in sortedlines: y.append(i[1]) grouplabels.append(i[0]) fig = p.figure() ax = fig.add_subplot(111) p.plot(x, y, 'bo' '-') p.ylabel("number of repeats") p.xlabel("states") lnr = float(max(y)) fp = lnr * .05 p.ylim([0 - fp, lnr + fp]) p.xlim([0 - fp, max(x) + fp]) ax.set_xticks(x) ax.set_xticklabels(grouplabels) self.rplotWindow.set_default_size(425, 425) container = gtk.VBox() self.rplotWindow.add(container) graph = drawArea(fig) toolbar = NavigationToolbar(graph, self.rplotWindow) container.pack_start(graph) container.pack_start(toolbar, False, False) self.rplotWindow.show_all()
def refreshGraphDisplay( self ): # Remove existing graph items if self.graphCanvas != None: self.vboxGraphs.remove( self.graphCanvas ) self.graphCanvas.destroy() self.graphCanvas = None if self.graphNavToolbar != None: self.vboxGraphs.remove( self.graphNavToolbar ) self.graphNavToolbar.destroy() self.graphNavToolbar = None # Draw the graphs self.graphFigure = Figure( figsize=(8,6), dpi=72 ) self.graphAxis = self.graphFigure.add_subplot( 111 ) #self.graphAxis.plot( range( 1, len( self.maxMotionCounts )+1 ), self.maxMotionCounts ) diffs = [ 0 ] + [ self.leftMostMotionList[ i+1 ] - self.leftMostMotionList[ i ] for i in range( len( self.leftMostMotionList ) - 1 ) ] #self.graphAxis.plot( range( 1, len( self.leftMostMotionList )+1 ), self.leftMostMotionList ) self.graphAxis.plot( range( 1, len( self.leftMostMotionList )+1 ), diffs ) # Build the new graph display self.graphCanvas = FigureCanvas( self.graphFigure ) # a gtk.DrawingArea self.graphCanvas.show() self.graphNavToolbar = NavigationToolbar( self.graphCanvas, self.window ) self.graphNavToolbar.lastDir = '/var/tmp/' self.graphNavToolbar.show() # Show the graph self.vboxGraphs.pack_start( self.graphNavToolbar, expand=False, fill=False ) self.vboxGraphs.pack_start( self.graphCanvas, True, True ) self.vboxGraphs.show() self.vboxGraphs.show()
def __init__(self): gladefile = 'fluviewer.glade' # This must match the window name in glade windowname = 'fluviewer' self.wTree = gtk.glade.XML(gladefile, windowname) dic = { # Also need to set fluviewer's signal tab 'on_fluviewer_destroy': gtk.main_quit, 'on_tv_country_button_release_event': self.on_tv_country_changed, 'on_tv_country_key_release_event': self.on_tv_country_changed, 'on_btn_update_clicked': self.on_btn_update_clicked, } self.wTree.signal_autoconnect (dic) self.fluviewer = self.wTree.get_widget('fluviewer') # Load CSV if it is in current directory self.update(False) self.reload() # Setting up figure self.figure = Figure() self.axis = self.figure.add_subplot(111) self.canvas = FigureCanvas(self.figure) vbox = self.wTree.get_widget('vbox2') vbox.pack_start(self.canvas, True, True) # Setting figure navigation toolbar vbox.pack_start(NavigationToolbar(self.canvas, self.fluviewer), False, False) vbox.show_all()
def energyplot(self, *args): table = open("%sstate_table" % config.path_states, "r") lines = table.readlines() x = [] y = [] grouplabels = [] for i in range(2, len(lines)): x.append(i - 1) y.append(float(lines[i].split()[1])) grouplabels.append(lines[i].split()[0]) y.reverse() grouplabels.reverse() self.eplotWindow.set_default_size(425, 425) fig = p.figure() ax = fig.add_subplot(111) ax.plot(x, y, 'bo' '-') p.xlabel("State") p.ylabel("eV") ax.set_xticks(x) ax.set_xticklabels(grouplabels) container = gtk.VBox() self.eplotWindow.add(container) graph = drawArea(fig) toolbar = NavigationToolbar(graph, self.eplotWindow) container.pack_start(graph) container.pack_start(toolbar, False, False) self.eplotWindow.show_all()
def __init__(self, xs, ys): self.xs=xs self.ys=ys self.win = gtk.Window() self.win.connect("destroy", lambda x: gtk.main_quit()) self.win.set_default_size(800,600) self.win.set_title("openSpectrometer") self.vbox = gtk.VBox() self.win.add(self.vbox) self.fig = Figure(figsize=(5,4), dpi=100) self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea self.ax = self.fig.add_subplot(111) self.canvas.mpl_connect('pick_event', self.onpick) self.vbox.pack_start(self.canvas) self.toolbar = NavigationToolbar(self.canvas, self.win) self.hbox = gtk.HBox() self.button=gtk.Button('Select this point as lambda max') self.button.connect("clicked", self.buttonClick) self.hbox.pack_start(self.toolbar) self.hbox.pack_start(self.button) self.vbox.pack_start(self.hbox, False, False) self.lastind = 0 self.text = self.ax.text(0.05, 0.95, 'Datapoint index selected: none', transform=self.ax.transAxes, va='top')
def __init__(self, NetworkTable): util.initialize_from_xml(self) self.dead = False self.plots = [] self.count = 0 self.netTable = NetworkTable self.netTable.PutBoolean('EnableTuning', True) self.figure = Figure(figsize=(5, 4), dpi=100) self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self.figure) # a gtk.DrawingArea self.graphImage = util.replace_widget(self.graphImage, self.canvas) self.toolbar = util.replace_widget( self.toolbar, NavigationToolbar(self.canvas, self.window)) self.window.show_all() # listen to network tables variables network_tables.attach_fn(self.netTable, "Catapult Values", self.on_update_CatapultValues, self.window) network_tables.attach_fn(self.netTable, "EnableTuning", self.on_update_EnableTuning, self.window)
def setup_plot(self, plot_controller): self.plot_controller = plot_controller self["matplotlib_box"].add(self.plot_controller.canvas) self["matplotlib_box"].show_all() self.nav_toolbar = NavigationToolbar(self.plot_controller.canvas, self.get_top_widget()) self.nav_toolbar.set_name("navtoolbar") self["navtoolbar"] = self.nav_toolbar self["navtoolbar_box"].add(self.nav_toolbar)
def __init__(self): self.widgets = gtk.glade.XML('mpl_with_glade.glade') self.widgets.signal_autoconnect(GladeHandlers.__dict__) self['windowMain'].connect('destroy', lambda x: gtk.main_quit()) self['windowMain'].move(10, 10) self.figure = Figure(figsize=(8, 6), dpi=72) self.axis = self.figure.add_subplot(111) t = arange(0.0, 3.0, 0.01) s = sin(2 * pi * t) self.axis.plot(t, s) self.axis.set_xlabel('time (s)') self.axis.set_ylabel('voltage') self.canvas = FigureCanvas(self.figure) # a gtk.DrawingArea self.canvas.show() self.canvas.set_size_request(600, 400) self.canvas.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK) self.canvas.set_flags(gtk.HAS_FOCUS | gtk.CAN_FOCUS) self.canvas.grab_focus() def keypress(widget, event): print('key press') def buttonpress(widget, event): print('button press') self.canvas.connect('key_press_event', keypress) self.canvas.connect('button_press_event', buttonpress) def onselect(xmin, xmax): print(xmin, xmax) span = SpanSelector(self.axis, onselect, 'horizontal', useblit=False, rectprops=dict(alpha=0.5, facecolor='red')) self['vboxMain'].pack_start(self.canvas, True, True) self['vboxMain'].show() # below is optional if you want the navigation toolbar self.navToolbar = NavigationToolbar(self.canvas, self['windowMain']) self.navToolbar.lastDir = '/var/tmp/' self['vboxMain'].pack_start(self.navToolbar) self.navToolbar.show() sep = gtk.HSeparator() sep.show() self['vboxMain'].pack_start(sep, True, True) self['vboxMain'].reorder_child(self['buttonClickMe'], -1)
def make_figure(win): """ Create a figure with toolbar and associated boxes. Return the figure, toolbar, and encapsulating box. """ fig = Figure() FigureCanvas(fig) toolbar = NavigationToolbar(fig.canvas, win) image_box = gtk.VBox() image_box.pack_start(fig.canvas) image_box.pack_start(toolbar, False, False) return fig, toolbar, image_box
def __init__(self, label): self.plots = dict() gtk.Frame.__init__(self) self.set_label(label) self.fig = Figure(figsize=(6, 4)) self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea #self.add(self.canvas) vbox = gtk.VBox() vbox.pack_start(self.canvas) toolbar = NavigationToolbar(self.canvas, self) vbox.pack_start(toolbar, False, False) self.add(vbox)
def __init__(self, plotters, fields): gtk.VBox.__init__(self) self.figure = mpl.figure.Figure() self.canvas = FigureCanvas(self.figure) self.canvas.unset_flags(gtk.CAN_FOCUS) self.canvas.set_size_request(600, 400) self.pack_start(self.canvas, True, True) self.canvas.show() self.navToolbar = NavigationToolbar(self.canvas, self.window) #self.navToolbar.lastDir = '/tmp' self.pack_start(self.navToolbar, False, False) self.navToolbar.show() self.checkboxes = gtk.HBox(len(plotters)) self.pack_start(self.checkboxes, False, False) self.checkboxes.show() self.pol = (1 + 0j, 0j) self.pol2 = None self.handlers = [] i = 0 self.plots = [] for plotterClass, default in plotters: axes = self.figure.add_subplot(len(plotters), 1, i) def makeUpdateInfo(i): return lambda s: self.__updateInfo(i, s) def makeUpdatePos(i): return lambda s: self.__updatePos(i, s) plotter = plotterClass(axes, fields, makeUpdateInfo(i), makeUpdatePos(i)) d = PlottedData(axes, plotter, default, self.__updateChildren) self.checkboxes.pack_start(d.checkBox, False, False) self.plots.append(d) i += 1 self.__infos = [None] * len(self.plots) self.__posi = None self.legendBox = gtk.CheckButton("Show legend") self.legendBox.set_active(True) self.legendBox.connect("toggled", self.__on_legend_toggled) self.checkboxes.pack_start(self.legendBox, False, False) self.legendBox.show() self.__updateChildren()
def show(self): try: if not self.packed: #print 'packing' self.pack_start(self.canvas, expand=True) toolbar = NavigationToolbar(self.canvas, self.get_parent_window()) self.pack_start(toolbar, expand=False) self.packed = True #print 'packed' super(ZachFigureCanvas, self).show() except Exception, e: print 'Exception: ', e raise
def make_toolbar(self): toolbar = NavigationToolbar(self.canvas, self) next = 8 toolitem = gtk.SeparatorToolItem() toolitem.show() toolbar.insert(toolitem, next); next+=1 toolitem.set_expand(False) self.buttonFollowEvents = gtk.CheckButton () self.buttonFollowEvents.set_label('Auto') self.buttonFollowEvents.show() self.buttonFollowEvents.set_active(True) toolitem = gtk.ToolItem() toolitem.show() #Rewriting this for the new gtk tooltips available in pygtk 2.12 and up #toolitem.set_tooltip( # toolbar.tooltips, # 'Automatically update in response to selections in EEG', 'Private') toolitem.set_tooltip_text('Automatically update in response to selections in EEG') toolitem.add(self.buttonFollowEvents) toolbar.insert(toolitem, next); next +=1 # XXX: only available in gtk 2.6 menu = gtk.MenuToolButton(gtk.STOCK_EDIT) menu.show() context = self.make_context_menu() menu.set_menu(context) #menu.set_tooltip( # toolbar.tooltips, # 'Set filter/detrend etc', 'Private') menu.set_tooltip_text('Set filter/detrend etc') toolbar.insert(menu, next); next+=1 toolitem = gtk.SeparatorToolItem() toolitem.show() toolbar.insert(toolitem, next) toolitem.set_expand(False) return toolbar
def __init__(self, pp, progressbar): self.pp = pp self.pb = progressbar self.figure = pylab.figure() self.canvas = FigureCanvas(self.figure) self.toolbar = NavigationToolbar(self.canvas, pp["MainWindow"]) self.pp["BoxPlotArea"].pack_start(self.toolbar, expand=False, fill=False) self.pp["BoxPlotArea"].pack_start(self.canvas, expand=True, fill=True) self.canvas.connect("button_press_event", self.on_button_press_event) self.l = 0 self.dataAreOld = True self.pathLength = None self.pathId = None self.dl = None
def __init__(self, xlabel, ylabel, width=500, height=500, dpi=75): """ :type xlabel: str :type ylabel: str :type width: int :type height: int :type dpi: int """ gtk.VBox.__init__(self) figure = Figure(figsize=(width, height), dpi=dpi) self.axes = figure.add_subplot(111, xlabel=xlabel, ylabel=ylabel) """ :type: matplotlib.axes.Axes """ self.axes.hold(False) self.canvas = FigureCanvas(figure) #self.canvas.mpl_connect('button_press_event', self.klick) nav = NavigationToolbar(self.canvas, self) self.pack_start(nav, False, False) self.pack_start(self.canvas)
def addPlot(self, name, plots): # print 'adding:',name,plots if self.fig: newfig = PlotFig(name, plots, None, self.sharedx) else: newfig = PlotFig(name, plots, None, None) self.sharedx = newfig.getSharedAxe() self.fig[name] = {} self.fig[name]['fig'] = newfig canvas = newfig.getCanvas() vbox = gtk.VBox() vbox.pack_start(canvas, True, True) toolbar = NavigationToolbar(canvas, self.ui) vbox.pack_start(toolbar, False, False) self.fig[name]['box'] = vbox self.table.attach(vbox, 0, 1, self.count, self.count + 1) self.count += 1 self.ui.show_all()
def __init__(self): self.widgets = gtk.glade.XML('test.glade') self.widgets.signal_autoconnect(GladeHandlers.__dict__) self['windowMain'].connect('destroy', lambda x: gtk.main_quit()) self['windowMain'].move(10, 10) self.figure = Figure(figsize=(8, 6), dpi=72) self.axis = self.figure.add_subplot(111) t = arange(0.0, 3.0, 0.01) s = sin(2 * pi * t) self.axis.plot(t, s) self.axis.set_xlabel('time (s)') self.axis.set_ylabel('voltage') self.canvas = FigureCanvas(self.figure) # a gtk.DrawingArea self.canvas.show() self.canvas.set_size_request(600, 400) def onselect(xmin, xmax): print xmin, xmax span = HorizontalSpanSelector(self.axis, onselect, useblit=False, rectprops=dict(alpha=0.5, facecolor='red')) self['vboxMain'].pack_start(self.canvas, True, True) self['vboxMain'].show() # below is optional if you want the navigation toolbar self.navToolbar = NavigationToolbar(self.canvas, self['windowMain']) self.navToolbar.lastDir = '/var/tmp/' self['vboxMain'].pack_start(self.navToolbar) self.navToolbar.show() sep = gtk.HSeparator() sep.show() self['vboxMain'].pack_start(sep, True, True) self['vboxMain'].reorder_child(self['buttonClickMe'], -1)
def new_figure(self, fig, identifier): with gtk.gdk.lock: window = gtk.Window() self.update_window_title(window, identifier) l, w = fig.get_size_inches() window.resize(int(l*100),int(w*100)) window.set_icon_from_file('lyse.svg') c = FigureCanvas(fig) v = gtk.VBox() n = NavigationToolbar(c,window) b = gtk.ToggleButton('Autoscale') v.pack_start(b,False,False) v.pack_start(c) v.pack_start(n,False,False) window.add(v) window.show_all() window.present() self.canvases.append(c) self.figures.append(fig) self.autoscaling[fig] = b self.windows[fig] = window
def create_ui(self): def _destroy(*args): self.stop_event.set() self.widget.connect('destroy', _destroy) vbox = gtk.VBox() self.widget.add(vbox) self.fig, self.axis = plt.subplots() canvas = FigureCanvas(self.fig) # a gtk.DrawingArea vbox.pack_start(canvas) toolbar = NavigationToolbar(canvas, self.widget) vbox.pack_start(toolbar, False, False) self.stop_event.clear() np.random.seed(0) # Use SI prefix and seconds units for x (i.e., time) axis. self.axis.xaxis.set_major_formatter(s_formatter) self.start_button = gtk.Button('Start') self.start_button.connect("clicked", lambda *args: self.start()) self.stop_button = gtk.Button('Pause') self.stop_button.connect("clicked", lambda *args: self.stop_event.set()) self.stop_button.props.sensitive = False self.clear_button = gtk.Button('Reset') self.clear_button.connect("clicked", lambda *args: self.reset()) self.clear_button.props.sensitive = False button_box = gtk.HBox() for widget_i in (self.start_button, self.stop_button, self.clear_button): button_box.pack_start(widget_i, False, False) vbox.pack_start(button_box, False, False) self.axis.set_xlabel('Time')
def energy_plot(self, *args): a = open("%sstate_table" % config.path_states, "r") b = a.readlines() x = [] y = [] for i in range(len(b)): y.append(float(b[i].split()[1])) for i in range(len(b)): x.append(i) self.plotWindow.set_default_size(600, 600) fig = p.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(x, y, '-' 'o') p.xlabel("State") p.ylabel("eV") container = gtk.VBox() self.plotWindow.add(container) graph = drawArea(fig) toolbar = NavigationToolbar(graph, self.plotWindow) container.pack_start(graph) container.pack_start(toolbar, False, False) self.plotWindow.show_all()
def refreshGraphDisplay(self): if self.canvas != None: self.hboxWorkArea.remove(self.canvas) self.canvas.destroy() self.canvas = None if self.navToolbar != None: self.vboxMain.remove(self.navToolbar) self.navToolbar.destroy() self.navToolbar = None self.canvas = FigureCanvas(self.figure) # a gtk.DrawingArea self.canvas.show() self.hboxWorkArea.pack_start(self.canvas, True, True) self.hboxWorkArea.show() # Navigation toolbar self.navToolbar = NavigationToolbar(self.canvas, self.window) self.navToolbar.lastDir = '/var/tmp/' self.vboxMain.pack_start(self.navToolbar, expand=False, fill=False) self.navToolbar.show() self.vboxMain.show()
def __init__(self, img_data): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete_event", self.delete_event) self.window.connect('key_press_event', self.on_key_press_event) self.window.set_default_size(400, 300) self.window.set_title("Gadgetron Image Viewer") self.vbox = gtk.VBox() self.window.add(self.vbox) self.fig = Figure(figsize=(5, 4), dpi=100) plt.gray() self.ax = self.fig.add_subplot(111) self.img_ax = self.ax.imshow(np.squeeze(np.abs(img_data))) self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea self.vbox.pack_start(self.canvas) self.toolbar = NavigationToolbar(self.canvas, self.window) self.vbox.pack_start(self.toolbar, False, False) self.window.show_all()
def __init__(self, x, x_label, title, width, height, num_series=3): gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL) if not x: print "No x values in plot" sys.exit(0) self.connect('destroy', lambda x: gtk.main_quit()) self.set_default_size(width, height) self.fig = Figure() self.ax = self.fig.add_subplot(111) self.offset = 0 self.set_title(title) self.ax.get_axes().set_xlabel(x_label) self.ax.get_axes().grid() if isinstance(x[0], str): self.fig.autofmt_xdate() canvas = FigureCanvas(self.fig) vbox = gtk.VBox() vbox.pack_start(canvas) toolbar = NavigationToolbar(canvas, self) vbox.pack_start(toolbar, False, False) self.add(vbox) self.x = x self.num_series = num_series
def create_ui(self): self.widget = gtk.Assistant() self.widget.connect("prepare", self.assistant_prepared) self.widget.connect("cancel", self.cancel_button_clicked) self.widget.connect("close", self.close_button_clicked) self.widget.connect("apply", self.apply_button_clicked) # # Introduction # box = gtk.HBox() self.widget.append_page(box) self.widget.set_page_type(box, gtk.ASSISTANT_PAGE_INTRO) self.widget.set_page_title(box, "Introduction") content = ('This wizard will guide you through the process of ' 'testing the channels of a single switching board.') label = gtk.Label(content) label.set_use_markup(True) label.set_line_wrap(True) image = gtk.Image() img_path = pkg_resources.resource_filename( 'dmf_control_board_firmware', 'gui/channels_intro.png') image.set_from_file(str(img_path)) box.pack_start(label, True, False, padding=15) box.pack_start(image, True, True, padding=5) self.widget.set_page_complete(box, True) # # Connect hardware # box = gtk.HBox() self.widget.append_page(box) self.widget.set_page_type(box, gtk.ASSISTANT_PAGE_CONTENT) self.widget.set_page_title(box, "Connect hardware") label = gtk.Label( ' - Connect DropBot "<tt>Out to Amp</tt>" to amplifier input.\n' ' - Connect amplifier output to DropBot "<tt>In from Amp</tt>".\n' ' - Connect a bank of DropBot channels to test board.') image = gtk.Image() img_path = pkg_resources.resource_filename( 'dmf_control_board_firmware', 'gui/impedance_feedback_setup.png') image.set_from_file(str(img_path)) label.set_line_wrap(True) label.set_use_markup(True) box.pack_start(label, True, False, padding=15) box.pack_start(image, True, True, padding=5) self.widget.set_page_complete(box, True) # # Select frequencies # self.radio_buttons = [ gtk.RadioButton(label='Channels %d-%d' % (c, c + self.channels_per_board - 1)) for c in xrange(0, self.channel_count, self.channels_per_board) ] for b in self.radio_buttons[1:]: b.set_group(self.radio_buttons[0]) box = gtk.VBox() for b in self.radio_buttons: box.pack_start(b, expand=False, fill=False, padding=20) self.widget.append_page(box) self.widget.set_page_type(box, gtk.ASSISTANT_PAGE_CONTENT) self.widget.set_page_title(box, "Select bank of test channels") self.widget.set_page_complete(box, True) ## # Record measurements # box1 = gtk.VBox() self.widget.append_page(box1) self.widget.set_page_type(box1, gtk.ASSISTANT_PAGE_PROGRESS) self.widget.set_page_title(box1, "Record measurements") self.measurements_label = gtk.Label('Ready.') self.measurements_label.set_line_wrap(True) self.measure_progress = gtk.ProgressBar() box1.pack_start(self.measurements_label, True, True, 0) box1.pack_start(self.measure_progress, expand=False, fill=False, padding=15) self.box1 = box1 ## # Display readings # box = gtk.VBox() self.widget.append_page(box) self.widget.set_page_type(box, gtk.ASSISTANT_PAGE_CONFIRM) self.widget.set_page_title(box, "Channel readings") self.figure = Figure(dpi=72) self.canvas = FigureCanvasGTK(self.figure) toolbar = NavigationToolbar(self.canvas, self.widget) box.pack_start(self.canvas) box.pack_start(toolbar, False, False) self.widget.set_page_complete(box, True) ### # Summary # box = gtk.VBox() self.widget.append_page(box) self.widget.set_page_type(box, gtk.ASSISTANT_PAGE_SUMMARY) self.widget.set_page_title(box, "Summary") label = gtk.Label('Testing of selected channels complete.') label.set_line_wrap(True) box.pack_start(label, True, True, 0) self.widget.set_page_complete(box, True)
def __init__(self): gladefile = "HurricaneUI.glade" builder = gtk.Builder() builder.add_from_file(gladefile) self.window = builder.get_object("mainWindow") builder.connect_signals(self) self.figure = Figure(figsize=(10, 10), dpi=75) self.axis = self.figure.add_subplot(111) self.lat = 50 self.lon = -100 self.globe = globDisp.GlobeMap(self.axis, self.lat, self.lon) self.canvas = FigureCanvasGTK(self.figure) self.canvas.show() self.canvas.set_size_request(500, 500) self.globeview = builder.get_object("map") self.globeview.pack_start(self.canvas, True, True) self.navToolbar = NavigationToolbar(self.canvas, self.globeview) self.navToolbar.lastDir = '/var/tmp' self.globeview.pack_start(self.navToolbar) self.navToolbar.show() self.gridcombo = builder.get_object("gridsize") cell = gtk.CellRendererText() self.gridcombo.pack_start(cell, True) self.gridcombo.add_attribute(cell, 'text', 0) #self.gridcombo.set_active(2) # read menu configuration self.gridopt = builder.get_object("gridopt").get_active() self.chkDetected = builder.get_object("detectedopt") self.detectedopt = self.chkDetected.get_active() self.chkHurricane = builder.get_object("hurricaneopt") self.hurricaneopt = self.chkHurricane.get_active() model = builder.get_object("liststore1") index = self.gridcombo.get_active() self.gridsize = model[index][0] radio = [ r for r in builder.get_object("classifieropt1").get_group() if r.get_active() ][0] self.sClassifier = radio.get_label() self.start = builder.get_object("startdate") self.end = builder.get_object("enddate") self.chkUndersample = builder.get_object("undersample") self.chkGenKey = builder.get_object("genKey") # disable unimplemented classifier selection builder.get_object("classifieropt2").set_sensitive(False) builder.get_object("classifieropt3").set_sensitive(False) builder.get_object("classifieropt4").set_sensitive(False) self.btnStore = builder.get_object("store") self.datapath = 'GFSdat' self.trackpath = 'tracks' builder.get_object("btnDatapath").set_current_folder(self.datapath) builder.get_object("btnTrackpath").set_current_folder(self.trackpath) self.btnDetect = builder.get_object("detect") # current operation status self.stormlocs = None self.detected = None self.clssfr = None # for test drawing functions if os.path.exists('demo.detected'): with open('demo.detected', 'r') as f: self.detected = pickle.load(f) self.stormlocs = pickle.load(f) self.chkHurricane.set_label( str(self.stormlocs.shape[0]) + " Hurricanes") self.chkDetected.set_label( str(self.detected.shape[0]) + " Detected") self.setDisabledBtns() # draw Globe self.drawGlobe()
def __init__(self, plot_title='', id_is_strain=1, header=None, strain_acc_list=None, category_list=None, data_matrix=None): """ 2008-01-10 use a paned window to wrap the scrolledwindow and the canvas so that the relative size of canvas to the scrolledwindow could be adjusted by the user. """ prog = gnome.program_init('DataMatrixGUI', '0.1') #this must be called before any initialization for gnome app program_path = os.path.dirname(__init__.__file__) xml = gtk.glade.XML(os.path.join(program_path, 'DataMatrixGUI.glade')) xml.signal_autoconnect(self) self.app1 = xml.get_widget("app1") self.app1.connect("delete_event", gtk.main_quit) self.app1.set_default_size(800, 1000) self.app1.set_title(plot_title) self.plot_title = plot_title self.id_is_strain = id_is_strain self.header = header self.strain_acc_list = strain_acc_list self.category_list = category_list self.data_matrix = data_matrix self.inputDataHeaders = None self.columnTypes = None self.columnHeaders = None self.columnEditableFlagList = None self.list2D = None self.vbox1 = xml.get_widget("vbox1") self.treeview_matrix = xml.get_widget("treeview_matrix") # matplotlib stuff fig = Figure(figsize=(8,8)) self.canvas = FigureCanvas(fig) # a gtk.DrawingArea self._idClick = self.canvas.mpl_connect('button_press_event', self.onUserClickCanvas) self.vpaned1 = xml.get_widget("vpaned1") self.vpaned1.add2(self.canvas) #self.vbox1.pack_start(self.canvas, True, True) self.ax = fig.add_subplot(111) self.treeview_matrix.connect('row-activated', self.plot_row) toolbar = NavigationToolbar(self.canvas, self.app1) self.vbox1.pack_start(toolbar, False, False) self.checkbutton_label_dot = xml.get_widget('checkbutton_label_dot') self.entry_dot_label_column = xml.get_widget('entry_dot_label_column') self.dataLabelColumnIndexAndSeparatorList = None self.dataLabelNumericItemIndexList = None self.entry_x_na = xml.get_widget('entry_x_na') self.entry_y_na = xml.get_widget('entry_y_na') self.entry_multiply_x = xml.get_widget('entry_multiply_x') self.entry_multiply_y = xml.get_widget('entry_multiply_y') self.entry_add_x = xml.get_widget('entry_add_x') self.entry_add_y = xml.get_widget('entry_add_y') self.entry_x_error = xml.get_widget("entry_x_error") self.entry_y_error = xml.get_widget("entry_y_error") self.checkbutton_logX = xml.get_widget('checkbutton_logX') self.checkbutton_logY = xml.get_widget('checkbutton_logY') self.checkButtonPlotOnlySelected = xml.get_widget('checkButtonPlotOnlySelected') self.entry_x_column = xml.get_widget('entry_x_column') self.entry_y_column = xml.get_widget('entry_y_column') self.entry_filters = xml.get_widget("entry_filters") #self.checkbutton_histLogX = xml.get_widget('checkbutton_histLogX') #self.checkbutton_histLogY = xml.get_widget('checkbutton_histLogY') self.entry_hist_column = xml.get_widget('entry_hist_column') self.entry_no_of_bins = xml.get_widget('entry_no_of_bins') self.entry_plot_title = xml.get_widget('entry_plot_title') self.entry_plot_title.set_text(self.plot_title) self.filechooserdialog_save = xml.get_widget("filechooserdialog_save") self.filechooserdialog_save.connect("delete_event", yh_gnome.subwindow_hide) self.entry_sampling_probability = xml.get_widget("entry_sampling_probability") self.filechooserdialog_open = xml.get_widget("filechooserdialog_open") self.filechooserdialog_open.connect("delete_event", yh_gnome.subwindow_hide) self.app1_appbar1 = xml.get_widget('app1_appbar1') self.app1_appbar1.push('Status Message.') #import gnome.ui has to be executed. self.treeview_matrix.connect('cursor-changed', self.update_no_of_selected, self.app1_appbar1) self.app1.show_all() self.xValuePreProcessor = None self.yValuePreProcessor = None self.x_error_column_index = None self.y_error_column_index = None self.typeName2PythonType = { "str": str, "string": str, "numeric":float, "number":float, "double":float, "float":float, "integer":int, "int":int}
def __init__(self): self._sample_rate = 44100.0 self._duration = 1.0 self._fft_size = 8192 self._need_redraw = True self._need_redraw_lock = threading.Lock() #Set the Glade file self._gladefile = "layout2.glade" self._xml = gtk.glade.XML(self._gladefile) #Get the Main Window, and connect the "destroy" event self._window = self._xml.get_widget("main_window") self._window.set_title( "Wavelab ~ Nsound-%d.%d.%d ~ %s" % (Nsound.NSOUND_VERSION_A, Nsound.NSOUND_VERSION_B, Nsound.NSOUND_VERSION_C, "http://nsound.sourceforge.net")) if self._window: self._window.connect("destroy", gtk.main_quit) menuitem = self._xml.get_widget("menu_file_quit") menuitem.connect("activate", gtk.main_quit) # Disable some of the menus for now menu = self._xml.get_widget("menu_file_new") menu.set_sensitive(False) menu = self._xml.get_widget("menu_file_save") menu.set_sensitive(False) menu = self._xml.get_widget("menu_file_saveas") menu.connect("activate", self.menu_save_as) # Disable the help for now. menu = self._xml.get_widget("menu_help") menu.set_sensitive(False) # Set text on menu_file_open menu = self._xml.get_widget("menu_file_open") menu.set_label("Open Reference") menu.connect("activate", self.open_reference) self._last_path = None self._reference_wave = None # Don't know how to get the default background color, so I'm hard # coding it here for now. fig_bg = (230.0 / 255.0, 221.0 / 255.0, 213.0 / 255.0) # Freq plot self.freq_fig = Figure(figsize=(12, 8), dpi=72, facecolor=fig_bg, edgecolor=fig_bg) self.freq_axis = self.freq_fig.add_subplot(111) self.freq_canvas = FigureCanvas(self.freq_fig) # a gtk.DrawingArea #~ self.freq_canvas.show() vbox = self._xml.get_widget("vbox_freq") vbox.pack_start(self.freq_canvas, True, True) navbar = NavigationToolbar(self.freq_canvas, self._window) vbox.pack_start(navbar, False, False) # Time plot self.time_fig = Figure(figsize=(12, 8), dpi=72, facecolor=fig_bg, edgecolor=fig_bg) self.time_axis = self.time_fig.add_subplot(111) self.time_canvas = FigureCanvas(self.time_fig) # a gtk.DrawingArea #~ self.time_canvas.show() vbox = self._xml.get_widget("vbox_time") vbox.pack_start(self.time_canvas, True, True) navbar = NavigationToolbar(self.time_canvas, self._window) vbox.pack_start(navbar, False, False) # Adjust bounding boxes self.freq_fig.subplots_adjust(left=0.10, right=0.95, top=0.95, bottom=0.18) self.time_fig.subplots_adjust(left=0.10, right=0.95, top=0.95, bottom=0.18) ####################################################################### # Get the oscillator vbox osc_vbox = self._xml.get_widget("vbox_oscillators") self._osc_widgets = [] # OSC1 osc = OscWidget(OscType.SINE, 0, "OSC1", False) osc.mute = False osc.volume = 1.0 osc.pitch = 440.0 osc.changed_callback = self.callback_widget_changed self._osc_widgets.append(osc) osc_vbox.add(osc) # OSC2 osc = OscWidget(OscType.SAWTOOTH, 1, "OSC2", True) osc.mute = True osc.volume = 1.0 osc.pitch = 440.0 osc.harmonics = 3 osc.sync = False osc.changed_callback = self.callback_widget_changed self._osc_widgets.append(osc) osc_vbox.add(osc) # OSC3 osc = OscWidget(OscType.SQUARE, 2, "OSC3", True) osc.mute = True osc.volume = 1.0 osc.pitch = 440.0 osc.harmonics = 3 osc.changed_callback = self.callback_widget_changed osc.sync = False self._osc_widgets.append(osc) osc_vbox.add(osc) # OSC4 osc = OscWidget(OscType.NOISE, 3, "OSC4", True) osc.mute = True osc.volume = 1.0 osc.changed_callback = self.callback_widget_changed self._osc_widgets.append(osc) osc_vbox.add(osc) # Create default oscillators self._oscillators = [None, None, None, None] for widget in self._osc_widgets: self.remake_oscillator(widget) ####################################################################### # Get the filter vbox filter_vbox = self._xml.get_widget("vbox_filters") self._filter_widgets = [] # Filter1 f = FilterWidget(IRType.IIR, FilterType.LOW_PASS, 0, "Filter1") f.enabled = False f.order = 2 f.fc_low = 440.0 f.ripple = 0.00 f.changed_callback = self.callback_widget_changed self._filter_widgets.append(f) filter_vbox.add(f) # Filter2 f = FilterWidget(IRType.IIR, FilterType.HIGH_PASS, 1, "Filter2") f.enabled = False f.order = 2 f.fc_high = 5000.0 f.ripple = 0.00 f.changed_callback = self.callback_widget_changed self._filter_widgets.append(f) filter_vbox.add(f) # Filter3 f = FilterWidget(IRType.IIR, FilterType.BAND_PASS, 2, "Filter3") f.enabled = False f.order = 6 f.fc_low = 4000.0 f.fc_high = 6000.0 f.ripple = 0.00 f.changed_callback = self.callback_widget_changed self._filter_widgets.append(f) filter_vbox.add(f) # Filter4 f = FilterWidget(IRType.IIR, FilterType.BAND_REJECT, 3, "Filter4") f.enabled = False f.order = 10 f.fc_low = 4000.0 f.fc_high = 6000.0 f.ripple = 0.00 f.changed_callback = self.callback_widget_changed self._filter_widgets.append(f) filter_vbox.add(f) # Create default oscillators self._filters = [None, None, None, None] for widget in self._filter_widgets: self.remake_filter(widget) ####################################################################### # hook up widgets self.freq_xscale_toggle = self._xml.get_widget("freq_xscale_toggle") self.fft_size_combobox = self._xml.get_widget("fft_size_combobox") ####################################################################### # Setup defaults self.fft_size_combobox.set_active(2) # 8192 ####################################################################### # Hook up callbacks self.freq_xscale_toggle.connect("toggled", self.callback_freq_xyscale, None) self.fft_size_combobox.connect("changed", self.callback_fft_size, None) # FFTransform self.fft = Nsound.FFTransform(self._sample_rate) self.fft.setWindow(Nsound.HANNING) self._noise = None gobject.timeout_add(500, self.update_plots) self._window.show_all()
def __init__(self): # init gtk::Window gtk.Window.__init__(self) self.set_default_size(600, 800) self.connect('destroy', lambda win: gtk.main_quit()) self.set_title('DOSEMATIC v0.1') # variable name -- TODO self.xvariable="Dose" self.xvar="D" self.xunits="Gy" self.yvariable="Yield" self.yvar="Y" self.yunits="" # main layout container main_eb = gtk.EventBox() # horizontal box hbox = gtk.HBox(False, 8) # vertical box VBOX = gtk.VBox(False, 0) main_eb.add(VBOX) #main_eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(red=60000,green=60000,blue=60000)) self.add(main_eb) vbox1 = gtk.VBox(False,8) hbox.pack_start(vbox1, True, True) top_band = gtk.HBox() bottom_band = gtk.HBox() top_eb = gtk.EventBox() bottom_eb = gtk.EventBox() top_eb.add(top_band) bottom_eb.add(bottom_band) top_eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0,0,0)) bottom_eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0,0,0)) l1 = gtk.Label('DOSEMATIC v1.0 --- beta testing --- module 1, basic view') l2 = gtk.Label('author: Maciej Lewicki [email protected], [email protected]') top_band.add(l1) bottom_band.add(l2) hruler = gtk.HSeparator() hruler2 = gtk.HSeparator() VBOX.pack_start(top_eb,False,False) VBOX.pack_start(hruler,False,True,5) VBOX.pack_start(hbox,True,True) VBOX.pack_start(hruler2,False,True,5) VBOX.pack_end(bottom_eb,False,False) # TEXT SCREEN______________________________________________________ self.text = gtk.TextView() # TEXT VIEW self.text.set_wrap_mode(gtk.WRAP_WORD) # wrap words self.scroll_text = gtk.ScrolledWindow() # into scrollable env self.scroll_text.set_shadow_type(gtk.SHADOW_ETCHED_IN) self.scroll_text.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) self.scroll_text.add(self.text) text_view_box = gtk.VBox(False,5) text_view_box.pack_start(self.scroll_text,True,True) #__________________________________________________________________ # ESTIMATOR________________________________________________________ estimator_box = gtk.HBox(False,5) self.estxt = gtk.TextView() self.estxt.set_wrap_mode(gtk.WRAP_WORD) self.scroll_estxt = gtk.ScrolledWindow() self.scroll_estxt.set_shadow_type(gtk.SHADOW_ETCHED_IN) self.scroll_estxt.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) self.scroll_estxt.add(self.estxt) label = gtk.Label(self.yvariable+' = ') entry = gtk.Entry() entry.set_text("0.00") button = gtk.Button('Estimate '+self.xvariable) button.connect('clicked',self.y_estimate,entry) combo = gtk.combo_box_new_text() combo.append_text("Method A") combo.append_text("Method B") combo.append_text("Method C-original") combo.append_text("Method C-simplified") self.method="Method C-simplified" combo.set_active(3) combo.connect('changed', self.on_method_changed) ruler = gtk.HSeparator() grid = gtk.Table(2,4) grid.attach(label, 0,1,0,1) grid.attach(entry, 1,2,0,1) grid.attach(button, 0,2,1,2) grid.attach(ruler,0,2,2,3) grid.attach(combo,0,2,3,4) estimator_box.pack_start(grid,False,False) estimator_box.pack_start(self.scroll_estxt,True,True) #__________________________________________________________________ # FUNCTION TAB_____________________________________________________ function_box = gtk.HBox(False,5) self.ftxt = gtk.TextView() self.ftxt.set_wrap_mode(gtk.WRAP_WORD) self.scroll_ftxt = gtk.ScrolledWindow() self.scroll_ftxt.set_shadow_type(gtk.SHADOW_ETCHED_IN) self.scroll_ftxt.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) self.scroll_ftxt.add(self.ftxt) label_Y = gtk.Label() label_Y.set_use_markup(True) label_Y.set_markup('Y = c + αD + βD<sup>2</sup>') self.entry_c = gtk.Entry() self.entry_c.set_width_chars(5) label_c = gtk.Label('c: ') self.entry_alpha = gtk.Entry() self.entry_alpha.set_width_chars(5) label_alpha = gtk.Label() label_alpha.set_use_markup(True) label_alpha.set_markup('α: ') self.entry_beta = gtk.Entry() self.entry_beta.set_width_chars(5) label_beta = gtk.Label() label_beta.set_use_markup(True) label_beta.set_markup('β: ') self.entry_sc = gtk.Entry() self.entry_sc.set_width_chars(5) label_sc = gtk.Label() label_sc.set_use_markup(True) label_sc.set_markup('σ(c): ') self.entry_salpha = gtk.Entry() self.entry_salpha.set_width_chars(5) label_salpha = gtk.Label() label_salpha.set_use_markup(True) label_salpha.set_markup('σ(α): ') self.entry_sbeta = gtk.Entry() self.entry_sbeta.set_width_chars(5) label_sbeta = gtk.Label() label_sbeta.set_use_markup(True) label_sbeta.set_markup('σ(β): ') table_f = gtk.Table(6,3) #table_f.attach(label_Y, False, False) table_f.attach(label_c,0,1,0,1) table_f.attach(self.entry_c,1,2,0,1) table_f.attach(label_alpha,0,1,1,2) table_f.attach(self.entry_alpha,1,2,1,2) table_f.attach(label_beta,0,1,2,3) table_f.attach(self.entry_beta,1,2,2,3) table_f.attach(label_sc,4,5,0,1) table_f.attach(self.entry_sc,5,6,0,1) table_f.attach(label_salpha,4,5,1,2) table_f.attach(self.entry_salpha,5,6,1,2) table_f.attach(label_sbeta,4,5,2,3) table_f.attach(self.entry_sbeta,5,6,2,3) vruler = gtk.VSeparator() table_f.attach(vruler,3,4,0,3,xpadding=10) check_function = gtk.CheckButton("Plot function") check_points = gtk.CheckButton("Plot data points") check_err = gtk.CheckButton("Plot uncertainty band") check_ci_curve = gtk.CheckButton("Plot CI95% band (curve)") check_ci_points = gtk.CheckButton("Plot CI95% band (points)") check_function.set_active(True) check_points.set_active(True) check_err.set_active(True) check_ci_curve.set_active(True) check_ci_points.set_active(True) vbox_checks = gtk.VBox(False, 5) vbox_checks.pack_start(check_function, False, False) vbox_checks.pack_start(check_points, False, False) vbox_checks.pack_start(check_err, False, False) vbox_checks.pack_start(check_ci_curve, False, False) vbox_checks.pack_start(check_ci_points, False, False) check_function.connect('toggled',self.on_toggled, 'function') check_points.connect('toggled',self.on_toggled, 'points') check_err.connect('toggled',self.on_toggled, 'err') check_ci_curve.connect('toggled',self.on_toggled, 'ci_curve') check_ci_points.connect('toggled',self.on_toggled, 'ci_points') hbox_buttons = gtk.HBox(True,5) button_save_f = gtk.Button("Save Funtion") button_load_f = gtk.Button("Load Funtion") hbox_buttons.pack_start(button_save_f,True,True) hbox_buttons.pack_start(button_load_f,True,True) button_save_f.connect('clicked',self.save_function) button_load_f.connect('clicked',self.load_function) left_box = gtk.VBox(False,5) ruler_f1 = gtk.HSeparator() ruler_f2 = gtk.HSeparator() left_box.pack_start(label_Y, False, False) left_box.pack_start(table_f, False, False) left_box.pack_start(ruler_f1, False, True, 5) left_box.pack_start(vbox_checks, False, False) left_box.pack_start(ruler_f2, False, True, 5) left_box.pack_start(hbox_buttons, False, True) function_box.pack_start(left_box, False, False) function_box.pack_start(self.scroll_ftxt, True, True) #__________________________________________________________________ # NOTEBOOK WRAP____________________________________________________ self.notebook = gtk.Notebook() self.notebook.append_page(text_view_box, gtk.Label('Log console')) self.notebook.append_page(estimator_box, gtk.Label('Estimator')) self.notebook.append_page(function_box, gtk.Label('Calibration function')) vbox1.pack_end(self.notebook,True,True) #__________________________________________________________________ # MAT-PLOT-LIB_____________________________________________________ self.fig = Figure(figsize=(6, 4)) # create fig self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea self.canvas.set_size_request(600,400) # set min size self.markers = ['.',',','+','x','|','_','o', 'v', '^', '<', '>', '8', 's', 'p', '*', 'h', 'H', 'D', 'd'] self.colors = ['black','blue','green','red','cyan','magenta','yellow','purple','white'] self.pstyle = ['bmh','s','6','red','0.8','black','2','black','0.3','','25','','','20','15','','','20','15'] self.styledict = {} self.styledict["style"]='bmh' self.styledict["point_style"]='s' self.styledict["point_size"]='6' self.styledict["point_color"]='red' self.styledict["point_alpha"]='0.8' self.styledict["line_color"]='black' self.styledict["line_width"]='2' self.styledict["band_color"]='black' self.styledict["band_alpha"]='0.3' self.styledict["title_size"]='25' self.styledict["xtitle_size"]='20' self.styledict["xlabel_size"]='15' self.styledict["ytitle_size"]='20' self.styledict["ylabel_size"]='15' self.nselec = [1,12,5,3,-1,0,-1,0,-1,-1,-1,-1,-1,-1] self.plot_labels = ["Foci per cell vs Dose", "Dose", "Foci per cell", " [Gy]", " []"] #print plt.style.available self.mode='quadratic' self.function = None if self.mode=='linear' : self.function = self.linear elif self.mode=='quadratic' : self.function = self.quadratic self.fit_toggle='active' self.points_toggle=1 self.function_toggle=1 self.err_toggle=1 self.ci_func_toggle=1 self.ci_points_toggle=1 self.plotting() # --- CORE plotting function --- toolbar = NavigationToolbar(self.canvas, self) toolbarbox = gtk.HBox() image = gtk.Image() image.set_from_stock(gtk.STOCK_PROPERTIES, gtk.ICON_SIZE_LARGE_TOOLBAR) options_button = gtk.Button() options_button.add(image) options_button.connect('clicked',self.mpl_options) image2 = gtk.Image() image2.set_from_stock(gtk.STOCK_REFRESH, gtk.ICON_SIZE_LARGE_TOOLBAR) refresh_button = gtk.Button() refresh_button.add(image2) refresh_button.connect('clicked',self.on_refresh_clicked) toolbarbox.pack_start(toolbar, True, True) toolbarbox.pack_end(options_button, False, True) toolbarbox.pack_end(refresh_button, False, True) vbox1.pack_start(toolbarbox, False, False) vbox1.pack_start(self.canvas, True, True) # into box layout
def main(): p = OptionParser() p.add_option("-t", "--title", dest="title", help="changes the title of the plot.") p.add_option("-b", "--bins", dest="bins", help="The number of bins in a heatmap.") p.add_option("", "--xbins", dest="binsX", help="The number of bins in a heatmap.") p.add_option("", "--ybins", dest="binsY", help="The number of bins in a heatmap.") p.add_option("-x", "--xlabel", dest="xlabel", help="changes the label of the x axes.") p.add_option("-y", "--ylabel", dest="ylabel", help="changes the label of the y axes.") p.add_option( "-f", "--filename", dest="filename", help="If set, the plot is saved to file. See --format to select ratio") (options, args) = p.parse_args() binsX, binsY = (50, 50) if hasattr(options, "binsX") and options.binsX: binsX = options.binsX if hasattr(options, "binsY") and options.binsY: binsY = options.binsY if hasattr(options, "bins") and options.bins: binsX = options.bins binsY = options.bins title = "use -t to add a title" if hasattr(options, "title") and options.title: title = options.title xlabel = "use -x to add a xlabel" if hasattr(options, "xlabel") and options.xlabel: xlabel = options.xlabel ylabel = "use -y to add a ylabel" if hasattr(options, "ylabel") and options.ylabel: ylabel = options.ylabel xl = list() yl = list() for line in open(options.filename): s = line.split('\t') xl.append(s[0]) yl.append(s[1]) #x = np.random.normal(3, 1, 100000) x = np.array(xl, np.float32) print "x: " + str(x) #y = np.random.normal(1, 1, 100000) y = np.array(yl, np.float32) print "y: " + str(y) #H, xedges, yedges = np.histogram2d(y, x, bins=(xedges, yedges)) # Create plots fig = plt.figure() ax = fig.add_subplot(111) ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) #H, xedges, yedges = np.histogram2d(y, x, bins=int(options.bins)) #im = plt.imshow(H, interpolation='hanning', origin='low', extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])#extent=[0,1,0,1]) im = plot_heatmap(x, y, binsX, binsY, False) cb = fig.colorbar(im) win = gtk.Window() win.connect("destroy", lambda x: gtk.main_quit()) win.set_default_size(800, 600) win.set_title("Advanced Plotting GUI") font = {'family': 'liberation serif', 'weight': 'normal', 'size': 12} mpl.rc('font', **font) vbox = gtk.VBox() win.add(vbox) canvas = FigureCanvas(fig) # a gtk.DrawingArea vbox.pack_start(canvas) hbox = gtk.HBox(homogeneous=False, spacing=0) toolbar = NavigationToolbar(canvas, win) toolbox = gtk.VBox() toolbox.pack_start(toolbar, True, True) hbox.pack_start(toolbox, True, True) # add font size text box label_biningX = gtk.Label("Bin Size X:") adjustmentX = gtk.Adjustment(value=float(binsX), lower=1, upper=100000, step_incr=1, page_incr=10, page_size=0) entry_biningX = gtk.SpinButton(adjustment=adjustmentX, climb_rate=1, digits=0) entry_biningX.set_value(int(binsX)) entry_biningX.connect("value-changed", entry_biningX_changed, entry_biningX, []) label_biningY = gtk.Label("Y:") adjustmentY = gtk.Adjustment(value=float(binsY), lower=1, upper=100000, step_incr=1, page_incr=10, page_size=0) entry_biningY = gtk.SpinButton(adjustment=adjustmentY, climb_rate=1, digits=0) entry_biningY.set_value(int(binsY)) entry_biningY.connect("value-changed", entry_biningY_changed, entry_biningY, []) cmd_log = gtk.CheckButton(label="Log") cmd_log.connect("toggled", cmd_log_toggled, cmd_log, []) data = [canvas, x, y, cb, entry_biningX, entry_biningY, cmd_log] entry_biningX.set_data("data", data) entry_biningY.set_data("data", data) cmd_log.set_data("data", data) hbox.pack_start(label_biningX, False, False, 3) hbox.pack_start(entry_biningX, False, False, 5) hbox.pack_start(label_biningY, False, False, 3) hbox.pack_start(entry_biningY, False, False, 5) hbox.pack_start(cmd_log, False, False, 3) vbox.pack_start(hbox, False, False, 0) win.show_all()
win = gtk.Window() win.connect("destroy", lambda x: gtk.main_quit()) win.set_default_size(400, 300) win.set_title("Embedding in GTK") vbox = gtk.VBox() win.add(vbox) fig = Figure(figsize=(5, 4), dpi=100) ax = fig.add_subplot(111) t = arange(0.0, 3.0, 0.01) s = sin(2 * pi * t) ax.plot(t, s) canvas = FigureCanvas(fig) # a gtk.DrawingArea vbox.pack_start(canvas) toolbar = NavigationToolbar(canvas, win) vbox.pack_start(toolbar, False, False) def on_key_event(event): print('you pressed %s' % event.key) key_press_handler(event, canvas, toolbar) canvas.mpl_connect('key_press_event', on_key_event) win.show_all() gtk.main()