本文整理汇总了Python中matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg.get_width_height方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTKAgg.get_width_height方法的具体用法?Python FigureCanvasGTKAgg.get_width_height怎么用?Python FigureCanvasGTKAgg.get_width_height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg
的用法示例。
在下文中一共展示了FigureCanvasGTKAgg.get_width_height方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import get_width_height [as 别名]
class template:
def __init__(self):
self.builder = gtk.Builder()
self.builder.add_from_file(os.path.splitext(__file__)[0]+".glade")
self.window = self.builder.get_object("window")
dic = {
"on_toolbutton_refresh_clicked" : self.generate_testdata,
"on_button1_clicked" : self.generate_testdata,
"on_vboxMain_button_press_event" : self.button_press_event,
"on_vboxMain_button_release_event" : self.button_release_event,
"on_vboxMain_drag" : self.drag_begin,
"on_vboxMain_motion_notify_event" : self.drag_begin,
"on_toolbar_clear_clicked" : self.clear_selections,
"on_toolbar_zoomin_clicked" : self.zoomin_time,
"on_toolbar_zoomout_clicked" : self.zoomout_time,
"on_go_back_clicked" : self.go_back,
"on_go_forward_clicked" : self.go_forward,
"on_toolbutton_preferences_clicked" : self.preferences_open,
"on_button_pref_apply_activate" : self.pref_apply,
"set_channel_groups" : self.set_channel_groups,
}
self.builder.connect_signals(dic)
self.create_draw_frame('none')
self.space = 0
self.generate_testdata(None)
def create_draw_frame(self,widget):
self.fig = Figure(figsize=[100,100], dpi=72)
self.canvas = FigureCanvas(self.fig)
self.canvas.connect("scroll_event", self.scroll_event)
#self.canvas.connect('button_press_event', self.button_press_event)
self.canvas.show()
self.figure = self.canvas.figure
self.axes = self.fig.add_axes([0.045, 0.05, 0.93, 0.925], axisbg='#FFFFCC')
self.vb = self.builder.get_object("vboxMain")
self.vb.pack_start(self.canvas, gtk.TRUE, gtk.TRUE)
self.vb.show()
def preferences_open(self,widget):
self.win_prefs = self.builder.get_object("window_prefs")
self.win_prefs.show()
self.channel_tree(None)
def scroll_event(self, widget, event):
if event.direction == gdk.SCROLL_UP:
direction = 1
self.space = self.space + .1*self.scalefact
else:
direction = -1
self.space = self.space - .1*self.scalefact
if self.space < 0:
self.space = 0
print 'space', self.space
print (arange(0,size(self.data2plot,1))*(self.space))
self.space_data()
self.redraw(None)
curpos = self.axes.get_position()
l1 = curpos.x0
b1 = curpos.y0
w1 = curpos.x1
h1 = curpos.y1
def space_data(self):
self.data2plot = self.data[self.tstart:self.tstop,self.chanind] + \
(arange(0,size(self.data[self.tstart:self.tstop,self.chanind],1)) * \
(self.space))
def get_cursor_position(self,event):
ap = self.axes.get_position()
x,y = self.canvas.get_width_height()
posx = ((event.x/x)-ap.x0)*(1/(ap.x1-ap.x0))
posy = ((event.y/y)-(1-ap.y0))*(1/(ap.y0-ap.y1))
self.sx = (posx*(self.time[-1]-self.time[0]))+self.time[0]
self.sy = (posy*(self.data2plot.max()-self.data2plot.min()))+self.data2plot.min()
print self.sx, self.sy
def button_press_event(self,widget,event):
self.get_cursor_position(event)
print 'button pushed',event.button,event.type
if event.type == gtk.gdk.BUTTON_PRESS:
print "single click"
if event.button == 1:
#clicked line
#self.axes.axvline(x=self.sx)
self.xstart = self.sx
elif event.type == gtk.gdk._2BUTTON_PRESS:
print "double click"
#highlight channel
#self.axes.axhspan(self.sy-1, self.sy+1, xmin=0, xmax=1, color='yellow')
elif event.type == gtk.gdk._3BUTTON_PRESS:
print "triple click. ouch, you hurt your user."
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 2:
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import get_width_height [as 别名]
class _Matplotlib:
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 get_x_cursor_position(self,event):
gca = self.figure.gca ()
ap = gca.get_position ()
xmin, xmax = gca.get_xbound ()
x,y = self.canvas.get_width_height()
posx = ((event.x/x)-ap.x0)*(1/(ap.x1-ap.x0))
sx = (posx*(xmax - xmin)) + xmin
return sx
def on_button_press_event (self, w, event):
if not event.type == gtk.gdk._2BUTTON_PRESS \
or not event.button == 1:
return False
l = self.get_x_cursor_position(event)
self.pp ["PathScale"].set_value (l)
return True
def selectData (self, x, ys):
self.x = x
self.ys = ys
if not self.pathLength == self.pp.pathLength \
or not self.pathId == self.pp.pathId \
or not self.dl == self.pp.dl:
self.dataAreOld = True
self.pathId = self.pp.pathId
self.pathLength = self.pp.pathLength
self.dl = self.pp.dl
self.l = 0
self.datas = list ()
else:
self.dataAreOld = False
def init_pulse (self):
if self.dataAreOld:
self.pb.set_text ("Generating datas...")
self.pb.set_fraction (0)
glib.idle_add (self.getData_pulse)
else:
glib.idle_add (self.genPlot_pulse)
return False
def getData_pulse (self):
d = [ self.l, ]
d.extend (self.pp.client.problem.configAtParam (self.pathId, self.l))
self.datas.append (d)
self.l += self.dl
if self.l < self.pathLength:
self.pb.set_fraction (self.l / self.pathLength)
return True
else:
self.pb.set_fraction (1)
glib.idle_add (self.genPlot_pulse)
return False
def genPlot_pulse (self):
self.pb.set_text ("Generating plots...")
self.npdatas = np.matrix (self.datas)
self.figure.clf ()
gca = pylab.gca ()
for elt in self.ys:
pylab.plot (self.npdatas [:,self.x[1]], self.npdatas [:,elt[1]], label=elt[0])
gca.set_xlabel (self.x[0])
pylab.legend (loc='best')
self.canvas.draw ()
self.pb.set_text ("Idle")
return False
示例3: __init__
# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import get_width_height [as 别名]
#.........这里部分代码省略.........
self.View.set_model(self.dataList)
print 'adding channels'
def AddBoolColumn(self, title, columnId, viewtype):
self.render = gtk.CellRendererToggle()
self.render.set_property('activatable', True)
self.render.connect( 'toggled', self.checkit, self.dataList )
column = gtk.TreeViewColumn(title,self.render)#,text=columnId)
column.set_resizable(True)
column.add_attribute( self.render, "active", 2)
column.set_sort_column_id(columnId)
viewtype.append_column(column)
viewtype.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
def checkit(self,cell,path,model):
model[path][2] = not model[path][2]
print "Toggle '%s' to: %s" % (model[path][1], model[path][2],)
if model[path][2] == True:
x = model[path][0]
self.axes.scatter(self.data[1,x],self.data[0,x],marker='o',color='r')
self.canvas.draw()
self.get_checked_channels()
def AddListColumn(self, title, columnId, viewtype):
column = gtk.TreeViewColumn(title,gtk.CellRendererText(),text=columnId)
column.set_resizable(True)
column.set_sort_column_id(columnId)
viewtype.append_column(column)
viewtype.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
def selection_made(self,widget):
liststore,iter = self.View.get_selection().get_selected_rows()
self.channels_selected = [];
for i in iter:
x = liststore[i][0]
self.channels_selected.append(int(liststore[i][0])) #index to channels selected.
if liststore[i][2] == False:
scat = self.axes.scatter(self.data[1,x],self.data[0,x],marker='o',color='magenta')
try:
for j in self.previter:
if liststore[(j,)][2] == False:
x = liststore[(j,)][0]
scat = self.axes.scatter(self.data[1,x],self.data[0,x],marker='o')
except AttributeError:
print 'first click skip'
pass
self.previter = copy(iter)
#print 'prev',type(self.previter),self.previter
self.canvas.draw()
self.statusbar.push(self.statusbar_cid, 'Number of channels selected: '+str(len(self.channels_selected)))
def view_label_toggled(self,widget):
liststore = self.View.get_model()
if widget.get_active() == True:
for i in liststore:
xy = i[0]
label = i[1]
self.axes.text(self.data[1,xy],self.data[0,xy],label,fontsize=7)
else:
pass
self.canvas.draw()
def create_draw_frame(self,widget):
self.fig = Figure(figsize=[200,200], dpi=100)
self.canvas = FigureCanvas(self.fig)
self.canvas.show()
self.figure = self.canvas.figure
self.axes = self.fig.add_axes([0, 0, 1, 1], axisbg='#FFFFCC')
self.axes.axis('off')
self.vb = self.builder.get_object("viewport1")
self.vb.add(self.canvas)
self.vb.show()
self.axes.scatter(self.data[1],self.data[0],marker='o');#,facecolors='none');
def showpopupmenu(self,widget,event):
print('button ',event.button)
if event.button == 3:
m = self.builder.get_object("menufunctions")
print(widget, event)
m.show_all()
m.popup(None,None,None,3,0)
if event.button == 1:
ap = self.axes.get_position()
x,y = self.canvas.get_width_height()
posx = (event.x/x-.5)*(1/(ap.x1-ap.x0))*-1
posy = ((event.y/y-.5)*(1/(ap.y0-ap.y1)))
#posx = ((event.x/x)-ap.x0)*(1/(ap.x1-ap.x0))
#posy = ((event.y/y)-(1-ap.y0))*(1/(ap.y0-ap.y1))
print posx,posy
from meg import nearest
nx=nearest.nearest(self.data[0],posy)[0]
ny=nearest.nearest(self.data[1],posx)[0]
print nx,ny
def apply_selection(self, widget):
print 'Number of channels applied:',size(self.chanchecked,0)
self.result_handler(self.chanchecked)
return self.chanchecked
示例4: __init__
# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import get_width_height [as 别名]
#.........这里部分代码省略.........
if self.builder.get_object('toolbutton12').get_active() == True:
self.win_prefs.show()
else:
self.win_prefs.hide()
self.selections_tree(None)
def key_press_event(self, widget, event):
print event.keyval
def scroll_event(self, widget, event):
if event.direction == gdk.SCROLL_UP:
direction = 1
self.space = self.space + 2*self.scalefact
print 'sf',self.scalefact
else:
direction = -1
self.space = self.space - 2*self.scalefact
print 'sf',self.scalefact
if self.space < 0:
self.space = 0
print 'space', self.space
#print (arange(0,size(self.data2plot,1))*(self.space))
self.space_data()
self.redraw(None)
def space_data(self,space=None):
self.data2plot = self.data[self.tstart:self.tstop,self.chanind2plot]+\
(arange(0,size(self.data[self.tstart:self.tstop,self.chanind2plot],1))*\
(self.space))
def get_cursor_position(self,event):
ap = self.axes.get_position()
x,y = self.canvas.get_width_height()
posx = ((event.x/x)-ap.x0)*(1/(ap.x1-ap.x0))
posy = ((event.y/y)-(1-ap.y0))*(1/(ap.y0-ap.y1))
self.sx = (posx*(self.time[-1]-self.time[0]))+self.time[0]
self.sy = (posy*(self.data2plot.max()-self.data2plot.min())) + \
self.data2plot.min()
#print self.sx, self.sy
def button_press_event(self,widget,event):
self.get_cursor_position(event)
#print 'button pushed',event.button,event.type
if event.type == gtk.gdk.BUTTON_PRESS:
print "single click"
if event.button == 1:
self.xstart = self.sx
#elif event.type == gtk.gdk._2BUTTON_PRESS:
#print "double click"
#elif event.type == gtk.gdk._3BUTTON_PRESS:
#print "triple click. ouch, you hurt your user."
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 2:
closest_data = nearest.nearest(self.data2plot[0,:],self.sy)
print 'nearest',closest_data
print 'highlighting channel'
self.axes.axhspan(self.data2plot[:,closest_data].min(), \
self.data2plot[:,closest_data].max(), xmin=0, xmax=1, color='g',\
alpha=0.2)
self.canvas.draw()
self.specaxes.cla()
NFFT = 1024
Fs = self.srate #(1/self.srate)
print NFFT,int(Fs),'d'