本文整理汇总了Python中matplotlib.backends.backend_gtk.FigureCanvasGTK类的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTK类的具体用法?Python FigureCanvasGTK怎么用?Python FigureCanvasGTK使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FigureCanvasGTK类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: displayGraph
def displayGraph(self, xaxis, yaxis, hist):
if(hist == None):
return
try:
dialog = gtk.Window()
figure = Figure(figsize=(6,4), dpi=72)
axis = figure.add_subplot(111)
canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea
canvas.show()
dialog.add(canvas)
# empty axis if neccesary, and reset title and stuff
axis.clear()
axis.set_xlabel(xaxis)
axis.set_ylabel(yaxis)
if len(hist) > 1:
axis.plot(hist[0], 'r')
axis.plot(hist[1], 'g')
axis.plot(hist[2], 'b')
else:
axis.plot(hist[0], 'r')
dialog.show()
except ValueError:
sys.exit(1)
示例2: GtkTimeTicker
class GtkTimeTicker(TaskBaseWindow):
""" plot against time a specific item / set of items
Only works on arrays - so no singles!
"""
def __init__(self, tick_cb, title=None, dt=1.0, len=100, limits=None):
super(GtkTimeTicker, self).__init__(tick_cb=tick_cb, title=title, dt=dt)
self._no_given_limits = limits is None
self._len = len
self._fig = fig = Figure()
self._axis = axis = fig.add_subplot(111)
self._times = []
self._values = []
self._lines = []
self._gtkfig = FigureCanvasGTK(fig)
self._w.add(self._gtkfig)
self._w.set_size_request(300, 300)
self._w.show_all()
self._min_y, self._max_y = 0.0, 0.0
self._limits = limits
if limits:
self.setYLimits(*limits)
self._startTaskFirstTime()
def _update(self, result):
if len(result) == 0:
print "GtkTimeTicker: empty length result, nothing to do\r\n"
return
if len(result) > len(self._lines):
print "updating GtkTimeTicker to %s lines" % len(result)
for i in xrange(len(result) - len(self._lines)):
self._lines.append(self._axis.plot([],[])[0])
if len(self._values) != len(result):
# strange feature - if a new plot is added erase the old ones.
self._values = [[] for i in xrange(len(result))]
if self._limits:
self.setYLimits(*self._limits)
self._min_y, self._max_y = min(self._min_y, *result), max(self._max_y, *result)
self._times.append(time.time() - self._start)
for i, v in enumerate(result):
self._values[i].append(v)
if len(self._values[0]) > self._len:
for values in self._values:
del values[:(len(values) - self._len)]
del self._times[:(len(self._times) - self._len)]
self.updatePlot()
def updatePlot(self):
# TODO - better way then resetting the whole number of points.
for line, values in zip(self._lines, self._values):
line.set_data(self._times, values)
if len(line._x) != len(line._y):
import pdb; pdb.set_trace()
self._axis.set_xlim(self._times[0], self._times[-1])
if self._no_given_limits:
self.setYLimits(self._min_y, self._max_y)
self._gtkfig.draw()
def setYLimits(self, lim_min, lim_max):
self._axis.set_ylim(lim_min, lim_max)
示例3: __init__
def __init__(self):
self.lastUpdate = datetime.now()
self.thread = None
self.lastBest = None
self.builder = gtk.Builder()
self.builder.add_from_file(GUI_FILENAME)
# init default values (due to Glade 3.7 bug)
self.builder.get_object("input_Ax").set_value(brach.A[0])
self.builder.get_object("input_Ay").set_value(brach.A[1])
self.builder.get_object("input_Bx").set_value(brach.B[0])
self.builder.get_object("input_By").set_value(brach.B[1])
self.builder.get_object("input_population_size").set_value(brach.POPULATION_MAX)
self.builder.get_object("input_elitism").set_value(brach.ELITISM*100)
self.builder.get_object("input_points").set_value(brach.POINTS_INIT)
self.builder.get_object("input_crossover").set_value(brach.CROSSOVER*100)
self.builder.get_object("input_crossover_len").set_value(brach.CROSSOVER_LEN_MAX*100)
self.builder.get_object("input_mutation").set_value(brach.MUTATION*100)
self.builder.get_object("input_mutation_y").set_value(brach.MUTATION_Y*100)
self.builder.get_object("input_mutation_burst").set_value(brach.MUTATION_BURST*100)
# init the input_selection_type
selection_model = gtk.ListStore(str)
selection_model.append(["Tournament"])
selection_model.append(["Roulette"])
selection_box = self.builder.get_object("input_selection_type")
selection_box.set_model(selection_model)
cell = gtk.CellRendererText()
selection_box.pack_start(cell)
selection_box.add_attribute(cell,'text',0)
selection_box.set_active(0)
self.builder.get_object("button_save").set_sensitive(False)
self.running = False
# init graphs
self.fig_best = Figure(figsize=(400, 400))
self.fig_hist = Figure(figsize=(400, 200))
self.canvas_best = FigureCanvasGTK(self.fig_best)
self.canvas_hist = FigureCanvasGTK(self.fig_hist)
self.canvas_best.show()
self.canvas_hist.show()
self.hbox_best = self.builder.get_object("hbox_graph_best")
self.hbox_hist = self.builder.get_object("hbox_graph_hist")
self.hbox_best.pack_start(self.canvas_best, True, True)
self.hbox_hist.pack_start(self.canvas_hist, True, True)
# show window
self.builder.connect_signals(self)
window = self.builder.get_object('window_main')
window.set_title("Brachistochrone curve")
window.show()
示例4: __init__
class Onus:
def __init__(self):
#self.gladefile = "onus.glade"
self.gladefile = "../onus.glade"
self.wTree = gtk.glade.XML(self.gladefile, "mainWindow")
FILES = [ "../../0_10_0.TXT" ]
t = 0
time = []
heart_rate = []
step_count = []
activity = []
# Get the Data
for file in FILES:
infile = open(file,"r")
data_section = 0
while 1:
line = infile.readline()
if not line:
break
moment = line.split(",")
time.append( t )
t += 1
step_count.append( moment[0] )
heart_rate.append( moment[1] )
activity.append( moment[2] )
self.figure = Figure(figsize=(6,4), dpi=72)
self.axis = self.figure.add_subplot(111)
self.axis.set_xlabel('Time (minutes)')
self.axis.set_ylabel('Heart Rate (bpm)')
self.axis.set_title('Activity')
self.axis.grid(True)
self.axis.plot(time, heart_rate, time, step_count, time, activity)
self.axis.legend(["Heart Rate", "Step Count", "Activity"])
self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
self.canvas.show()
self.graphview = self.wTree.get_widget("vbox2")
self.graphview.pack_start(self.canvas, True, True)
#Create our dictionay and connect it
dic = { "on_mainWindow_destroy" : gtk.main_quit, "on_connect" : self.on_connect, "on_import" : self.on_import }
self.wTree.signal_autoconnect(dic)
def on_connect(self, widget):
#dan = Fetch()
#.start()
self.statusbar1 = self.wTree.get_widget("statusbar1")
self.statusbar1.push(0, "Connected")
def on_import(self, widget):
self.statusbar1 = self.wTree.get_widget("statusbar1")
self.statusbar1.push(0, "Importing")
示例5: init_chart
def init_chart(self):
self.figure = Figure(figsize=(6,4), dpi=72)
self.axis = self.figure.add_subplot(111)
self.axis.grid(True)
self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
self.canvas.show()
self.vbox.pack_start(self.canvas, True, True)
示例6: __init__
def __init__(self):
gladefile = os.path.join(roslib.packages.get_pkg_dir('pplan'), "glade/pplan_gui.glade")
self.windowname = "main_window"
self.w_tree = gtk.glade.XML(gladefile, self.windowname)
dic = {'on_main_window_destroy' : gtk.main_quit,
'on_get_data_button_clicked' : self.get_data,
'on_make_graph_button_clicked' : self.make_graph,
'on_calc_kernel_button_clicked' : self.calc_kernel,
'on_plan_path_button_clicked' : self.plan_path,
}
self.w_tree.signal_autoconnect(dic)
main_window = self.w_tree.get_widget('main_window')
# setup matplotlib stuff on first notebook page (empty graph)
self.figure = Figure(figsize=(6,4), dpi=72)
self.axis = self.figure.add_subplot(111)
self.axis.set_xlabel('Longitude')
self.axis.set_ylabel('Latitude')
self.axis.set_title('')
self.axis.grid(True)
self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
self.canvas.show()
self.graphview = self.w_tree.get_widget('vbox1')
self.graphview.pack_start(self.canvas, True, True)
self.nav_bar = NavigationToolbar(self.canvas, main_window)
self.graphview.pack_start(self.nav_bar, False, True)
run_dir = sys.argv[1]
self.settings = pplan.PPlanSettings(run_dir)
# initialize the data directory, if not done already
self.store = ppas.Store(self.settings.data_dir)
self.plot_graph()
self.plot_path()
示例7: createDBGraph
def createDBGraph(self, widget):
self.axis.clear()
self.axis.set_xlabel('Samples (n)')
self.axis.set_ylabel('Value (-)')
self.axis.set_title('Another Graph (click on the columnheader to sort)')
self.axis.grid(True)
# get columns from listmodel
age = []
for row in self.listmodel:
age.append(row[1])
size = []
for row in self.listmodel:
size.append(row[2])
# get number of rows
N = len(age)
ind = arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
p1 = self.axis.bar(ind, age, width, color='b')
p2 = self.axis.bar(ind+width, size, width, color='r')
# destroy graph if it already exists
while True:
try:
self.canvas2.destroy()
break
except:
print "nothing to destroy"
break
self.canvas2 = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
self.canvas2.show()
self.grahview = self.wTree.get_widget("vbox2")
self.grahview.pack_start(self.canvas2, True, True)
示例8: clouddetectsave
def clouddetectsave(self,obj):
dialog= gtk.FileChooserDialog("Save Cloud Detection Graph ",
None,
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
dialog.set_current_folder(os.curdir)
dialog.set_do_overwrite_confirmation(True)
filter = gtk.FileFilter()
filter.set_name("image(png) file")
filter.add_pattern("*.png")
dialog.add_filter(filter)
response=dialog.run()
if response == gtk.RESPONSE_OK:
plotimagefile=dialog.get_filename()
dialog.destroy()
#self.canvas1.print_figure1(plotimagefile, 72,'w', 'w','portrait')
self.figure1.savefig(plotimagefile)
self.canvas1.destroy()
self.canvas1 = FigureCanvasGTK(self.figure1)
self.graphview.pack_start(self.canvas1, True,True)
self.canvas1.show()
elif response == gtk.RESPONSE_CANCEL:
print "no file is selected"
dialog.destroy()
self.canvas1.show()
示例9: __init__
def __init__(self):
self.gladefile = "attenuation_calc.glade"
windowname = "MainWindow"
self.wTree=gtk.glade.XML(self.gladefile, windowname)
dic = { "on_GetDataButton_clicked" : self.button1_clicked,
"on_SaveImageMenuItem_activate" : self.save_image,
"on_ExportMenuItem_activate" : self.save_data,
"on_MainWindow_destroy" : (gtk.main_quit) ,
"on_QuitMenuItem_activate" : (gtk.main_quit),
"on_about_menuitem_activate" : self.about }
self.wTree.signal_autoconnect(dic)
self.figure = Figure(figsize=(6,4), dpi=72)
self.axis = self.figure.add_subplot(111)
self.axis.set_xlabel('Energies')
self.axis.set_ylabel('Attenuation Length (microns)')
self.axis.set_title('Attenuation Lengths vs Energy')
self.axis.grid(True)
self.canvas = FigureCanvasGTK(self.figure)
self.canvas.show()
self.graphview = self.wTree.get_widget("vbox1")
self.graphview.pack_start(self.canvas,True,True)
#self.graphview.pack_start(self.canvas,True,True)
self.wTree.get_widget(windowname).maximize()
self.E = {}
self.attlen = {}
return
示例10: __init__
def __init__(self):
# Le decimos a nuestro programa el nombre del archivo glade
self.widgets = gtk.glade.XML("interface.glade")
# Creamos un pequeño diccionario que contiene las señales definidas en
# glade y su respectivo método (o llamada)
signals = { "on_buttonIniciar_clicked" : self.on_buttonIniciar_clicked,
"on_about_dialog_clicked" : self.on_about_dialog_clicked,
"on_exit_clicked" : gtk.main_quit, # al presionar el boton salir, sale de la aplicacion
"gtk_main_quit" : gtk.main_quit } #
# Luego se auto-conectan las señales.
self.widgets.signal_autoconnect(signals)
# Nota: Otra forma de hacerlo es No crear el diccionario signals y
# solo usar "self.widgets.signal_autoconnect(self)" -->Ojo con el self
# Ahora obtenemos del archivo glade los widgets que vamos a utilizar
self.labelTiempo = self.widgets.get_widget("labelTiempo") #label de tiempo
self.buttonIniciar = self.widgets.get_widget("buttonIniciar") #boton iniciar
self.aboutDialog = self.widgets.get_widget("aboutDialog") #dialogo acerca de
#Definición del widget que manejará la gráfica
self.figure = Figure(figsize=(6,4), dpi=60)
self.axis = self.figure.add_subplot(111)
self.axis.set_xlabel('X')
self.axis.set_ylabel('Y')
self.axis.set_title('Graph')
self.axis.grid(True)
#Agregar la gráfica a la caja vertical
self.canvas = FigureCanvasGTK(self.figure)
self.canvas.show()
self.graphview = self.widgets.get_widget("matplot")
self.graphview.pack_start(self.canvas, True, True)
示例11: clear_figure
def clear_figure(self):
self.axes.clear()
self.canvas.destroy()
self.axes.grid(True)
self.canvas = FigureCanvasGTK(self.figure)
self.canvas.show()
self.widget.pack_start(self.canvas, True, True)
示例12: power_spectrum
def power_spectrum(self, x, n, fs):
self.axes.clear()
self.axes.grid(True)
self.axes.psd(x, NFFT = n, Fs = fs)
self.canvas.destroy()
self.canvas = FigureCanvasGTK(self.figure)
self.canvas.show()
self.widget.pack_start(self.canvas, True, True)
示例13: autocor
def autocor(self, x):
self.axes.clear()
self.axes.grid(True)
self.axes.acorr(x)
self.canvas.destroy()
self.canvas = FigureCanvasGTK(self.figure)
self.canvas.show()
self.widget.pack_start(self.canvas, True, True)
示例14: semilogy
def semilogy(self, x, y):
self.axes.clear()
self.axes.grid(True)
self.axes.semilogy(x, y)
self.canvas.destroy()
self.canvas = FigureCanvasGTK(self.figure)
self.canvas.show()
self.widget.pack_start(self.canvas, True, True)
示例15: draw
def draw(self):
'Draw or re-draw the plot, possibly showing some labels'
try: self.graphview.remove(self.canvas)
except: pass
self.canvas = FigureCanvasGTK(self.figure)
self.canvas.mpl_connect('pick_event', self.pick_handler)
self.canvas.show()
self.graphview = self.app.tree.get_widget("vbox_plot")
self.graphview.pack_start(self.canvas, True, True)