本文整理汇总了Python中matplotlib.backends.backend_gtk.FigureCanvasGTK.mpl_connect方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTK.mpl_connect方法的具体用法?Python FigureCanvasGTK.mpl_connect怎么用?Python FigureCanvasGTK.mpl_connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_gtk.FigureCanvasGTK
的用法示例。
在下文中一共展示了FigureCanvasGTK.mpl_connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ComponentChooser
# 需要导入模块: from matplotlib.backends.backend_gtk import FigureCanvasGTK [as 别名]
# 或者: from matplotlib.backends.backend_gtk.FigureCanvasGTK import mpl_connect [as 别名]
class ComponentChooser(gtk.Window):
"""Used for selecting components to use for remixing"""
components = None # Contains the components to choose from
data = None # Contains the original data
choose_mask = []
def __init__(self, _components = None, _data=None):
self.components = _components
self.data = _data
gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL)
self.set_default_size(700,500)
self.set_title("Choose components to use...")
self.connect("delete_event", self.delete_event)
self.connect("destroy", self.delete_event)
self.vbox = gtk.VBox()
self.add(self.vbox)
self.f = Figure(figsize=(5,4), dpi=100, subplotpars=SubplotParams(left=0.06, top=0.95, right=0.97, bottom=0.1))
self.setupSubplots()
self.plotAll()
self.canvas = FigureCanvas(self.f)
self.canvas.mpl_connect('button_press_event', self.cb_canvas)
self.vbox.pack_start(self.canvas)
self.toolbar = NavigationToolbar( self.canvas, self.window )
self.vbox.pack_start(self.toolbar, False, False)
self.show_all()
def delete_event(self, widget, event, data=None):
self.hide()
return True
def cb_canvas(self, event):
"""Called when the figure is clicked."""
#print event.button
if event.button == 3:
for i,a in enumerate(self.axs):
if event.inaxes == a:
#print "Subplot %i geclickt" % i
self.choose_mask[i] = bool(True-self.choose_mask[i])
#print self.choose_mask[i]
#a.grid()
a.cla()
#TODO: plotte...
a.plot(self.components[:,i])
#
if not self.choose_mask[i]:
a.text(numpy.array(a.get_xlim()).mean(),numpy.array(a.get_ylim()).mean(),"X",horizontalalignment='center',verticalalignment='center',fontsize=20,color="red")
self.canvas.draw()
def setupSubplots(self):
self.f.clear()
try:
ncols = 4
nrows = self.components.shape[1]/ncols +1
self.axs = []
self.choose_mask = []
for i in range(self.components.shape[1]):
self.axs.append(self.f.add_subplot(nrows,ncols,i+1))
self.choose_mask.append(True)
except Exception, e:
print "Error while setting up subplots", e
示例2: __init__
# 需要导入模块: from matplotlib.backends.backend_gtk import FigureCanvasGTK [as 别名]
# 或者: from matplotlib.backends.backend_gtk.FigureCanvasGTK import mpl_connect [as 别名]
class JPlot:
"""Misspecification plot"""
def __init__(self, app):
#setup matplotlib stuff on first notebook page (empty graph)
self.app = app
# Plot defaults:
self.imp_col = '#dd2244'
self.nim_col = '#5533dd'
# Create figure
self.figure = Figure(figsize=(6,4), dpi=72)
self.axis = self.figure.add_subplot(111)
self.axis.set_xlabel('Modification index')
self.axis.set_ylabel('Power')
self.axis.set_title('Misspecifications')
try:
# omit missing observations
parameters = [par for par in self.app.get_parameters() if \
par.mi <99.0 and par.power < 1.0 and par.epc < 99.0]
self.mis = [par.mi for par in parameters]
self.names = [par.name for par in parameters]
self.powers = [par.power for par in parameters]
self.ids = ["%s in group %s" % (par.name, par.group) for par in parameters]
self.axis.scatter( self.mis, self.powers,
c = [par.epc > self.app.get_field_value('delta') \
and self.imp_col or self.nim_col for par in parameters],
linewidth=0, picker=30.0, vmin=self.imp_col,
vmax = self.nim_col,
)
self.axis.autoscale_view(True) #tight
self.axis.axvline(self.app.get_critical(),
color='#444444', linestyle='dashed')
self.axis.axhline( y=float(self.app.get_field_value('power')),
color='#444444', linestyle='dashed')
except AttributeError:
pass
self.draw()
def pick_handler(self, event):
'''What happens if the user clicks a point in the plot'''
index = event.ind[0]
label = self.ids[index]
sys.stderr.write('ind is %s'% index)
sys.stderr.write('mousover %s\n' % label)
x, y = self.mis[index], self.powers[index]
self.axis.text(x, y, label)
self.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)
def reload(self):
'Completely redo the whole plot.'
self.graphview.remove(self.canvas)
self.__init__(self.app)