本文整理汇总了Python中matplotlib.backends.backend_wxagg.FigureCanvasWxAgg.mpl_connect方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasWxAgg.mpl_connect方法的具体用法?Python FigureCanvasWxAgg.mpl_connect怎么用?Python FigureCanvasWxAgg.mpl_connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_wxagg.FigureCanvasWxAgg
的用法示例。
在下文中一共展示了FigureCanvasWxAgg.mpl_connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_canvas
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
def _create_canvas(self, parent):
panel = QtGui.QWidget()
def mousemoved(event):
if event.xdata is not None:
x, y = event.xdata, event.ydata
name = "Axes"
else:
x, y = event.x, event.y
name = "Figure"
panel.info.setText("%s: %g, %g" % (name, x, y))
panel.mousemoved = mousemoved
vbox = QtGui.QVBoxLayout()
panel.setLayout(vbox)
mpl_control = FigureCanvas(self.value) #❷
vbox.addWidget(mpl_control)
if hasattr(self.value, "canvas_events"):
for event_name, callback in self.value.canvas_events:
mpl_control.mpl_connect(event_name, callback)
mpl_control.mpl_connect("motion_notify_event", mousemoved)
if self.factory.toolbar: #❸
toolbar = Toolbar(mpl_control, panel)
vbox.addWidget(toolbar)
panel.info = QtGui.QLabel(panel)
vbox.addWidget(panel.info)
return panel
示例2: MtracePlotPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class MtracePlotPanel(wx.Frame):
def __init__(self, manager, name, mtrace_data):
wx.Frame.__init__(self, manager, -1, name)
self._manager = manager
self._data = mtrace_data
self.Bind(wx.EVT_CLOSE, self.on_close)
self.create_main_canvas()
def init_plot(self):
self.dpi = 100
rc = matplotlib.figure.SubplotParams(left=0.05, bottom=0.05, right=0.99, top=0.95, wspace=0.001, hspace=0.1)
self.fig = Figure((3.0, 3.0), dpi=self.dpi, subplotpars=rc)
num_sub_plots = len(self._data)
fp = matplotlib.font_manager.FontProperties(size=10)
for i, subplot in enumerate(self._data):
subplot_val = 100 * num_sub_plots + 10 + i + 1
axes = self.fig.add_subplot(subplot_val)
axes.set_axis_bgcolor('white')
pylab.setp(axes.get_xticklabels(), fontsize=6)
pylab.setp(axes.get_yticklabels(), fontsize=8)
for data in subplot:
axes.plot(data.xdata,
data.ydata,
data.color,
linewidth = 1,
picker = 5,
label = data.legend
)[0]
axes.legend(loc='best', prop=fp)
axes.grid(True, color='gray')
pylab.setp(axes.get_xticklabels(), visible=True)
def onpick(self, event = None):
pass
def create_main_canvas(self):
self.init_plot()
self.canvas = FigCanvas(self, -1, self.fig)
self.canvas.mpl_connect('pick_event', self.onpick)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)
#self.add_toolbar()
def on_close(self, event):
self.Destroy()
pass
示例3: MplCanvasFrame
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class MplCanvasFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, title='Matplotlib in Wx', size=(600, 400))
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.panel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.EXPAND|wx.ALL)
self.sizerPanel = wx.BoxSizer(wx.VERTICAL)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.x = np.arange(0, 6, .01)
x = self.x
self.y = np.sin(x**2)*np.exp(-x)
y = self.y
self.canvas = FigureCanvas(self.panel, wx.ID_ANY, self.figure)
self.sizerPanel.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
#cursor = SnaptoCursor(self.canvas, self.axes, 0, 0)
#self.canvas.mpl_connect('motion_notify_event', cursor.mouse_move)
self.canvas.mpl_connect('motion_notify_event', self.onMouseMove)
self.axes.plot(x, y)
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
self.sizerPanel.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.Show()
self.panel.SetSizer(self.sizerPanel)
self.sizer.Add(self.panel, 0, wx.EXPAND | wx.ALL)
self.SetSizer(self.sizer)
self.Fit()
def onMouseMove(self, event):
self.axes.clear() # clear for redraw
lx = self.axes.axhline(color='k') # the horiz line
ly = self.axes.axvline(color='k') # the vert line
txt = self.axes.text(0.7, 0.9, '', transform=self.axes.transAxes)
if not event.inaxes: return
x, y = event.xdata, event.ydata
# update the line positions
lx.set_ydata(y)
ly.set_xdata(x)
txt.set_text('x=%1.2f, y=%1.2f' % (x,y))
self.axes.plot(self.x, self.y)
self.canvas.draw()
self.panel.Refresh()
def saveFigure(self, name):
format = 'eps'
self.figure.savefig(name+'.'+format, format=format)
示例4: SpectrumPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class SpectrumPanel(wx.Panel):
def __init__(self, parent, xlabel='m/z', ylabel='Intensity'):
wx.Panel.__init__(self, parent)
#
self.parent = parent
self.xlabel = xlabel
self.ylabel = ylabel
self.SetBackgroundColour("white")
#
self.figure = Figure()
self.canvas = FigureCanvas(self, -1, self.figure)
#
self.add_toolbar()
#
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP| wx.GROW| wx.EXPAND)
sizer.Add(self.toolbar, 0, wx.LEFT)
self.canvas.mpl_connect('motion_notify_event', self.on_motion)
self.SetSizer(sizer)
self.Fit()
self.clean()
#
def add_toolbar(self):
""
self.toolbar = NavigationToolbar2Wx(self.canvas)
mass_txt = wx.StaticText(self.toolbar, label='m/z', pos=(230, 7),
size=(25, 17))
mass_txt.SetBackgroundColour("light gray")
self.mass = wx.TextCtrl(self.toolbar, pos=(260,4), size=(50, 22),
style=wx.TE_READONLY)
#
self.toolbar.SetToolBitmapSize(wx.Size(24, 25))
self.toolbar.SetMinSize((1500, 31))
self.toolbar.Realize()
self.toolbar.Update()
#
def clean(self):
""
self.figure.clear()
self.axes = self.figure.add_subplot(111)
#
def dibuja(self):
"dibuja el canvas"
self.axes.set_xlabel(self.xlabel)
self.axes.set_ylabel(self.ylabel)
self.canvas.draw()
#
def on_motion(self, evt):
if evt.inaxes:
xpos = evt.xdata
self.mass.SetValue(' %0.1f' % (xpos))
print evt.xdata,evt.ydata
示例5: CanvasPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class CanvasPanel(wx.Panel):
def __init__(self, parent):
#invoke base class init
wx.Panel.__init__(self, parent)
self.fig = plt.Figure()
self.axes = self.fig.add_subplot(1, 1, 1)
#self.axes.set_title('hey'), #set_xlabel, set_ylabel
#canvas deceleration
self.canvas = FigureCanvas(self, -1, self.fig)
self.canvas.mpl_connect('motion_notify_event', self.update_status_bar_coordinates)
#toolbar deceleration
self.toolbar = MyCustomToolbar(self.canvas)
self.toolbar.Realize()
self.toolbar.update()
#x,y textbox deceleration
self.stCoordLabel = wx.StaticText(self, id=wx.NewId(), label="\n", style=wx.ALIGN_RIGHT)
#toolbar sizer
self.toolbarSizer = wx.BoxSizer(wx.HORIZONTAL)
self.toolbarSizer.Add(self.toolbar, proportion=0, flag=wx.ALIGN_LEFT)
self.toolbarSizer.Add(self.stCoordLabel, proportion=1, flag=wx.ALIGN_RIGHT)
#Main Sizer
sizer = wx.BoxSizer(wx.VERTICAL)
#add canvas to sizer
sizer.Add(self.canvas, proportion=1, flag=wx.EXPAND)
#add spacer
sizer.AddStretchSpacer(10)
#add toolbar and text sizer
sizer.Add(self.toolbarSizer, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL|wx.EXPAND, border=2)
self.SetSizer(sizer)
def refresh_plot(self, is_resize=True):
# get the axes
axes = self.canvas.figure.axes[0]
if (is_resize is True):
#resize canvas
axes.relim(visible_only=True)
axes.autoscale()
axes.autoscale_view()
#redraw canvas
self.canvas.draw()
def update_status_bar_coordinates(self, event):
if event.inaxes:
x, y = event.xdata, event.ydata
self.stCoordLabel.SetLabel("x = %f\ny = %f" % (x,y))
self.toolbarSizer.Layout()
else:
self.stCoordLabel.LabelText = ""
示例6: CanvasPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class CanvasPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
self.canvas.mpl_connect('motion_notify_event', parent.updateStatusBar)
self.NavigationToolbar = NavigationToolbar(self.canvas)
self.axes.set_autoscale_on(True)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.NavigationToolbar, 0, wx.ALL, 5)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW, 5)
self.SetSizer(self.sizer)
示例7: PanelGraph
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class PanelGraph(wx.Panel):
def __init__(self, parent, main):
self.main = main
wx.Panel.__init__(self, parent)
self.figure = matplotlib.figure.Figure(facecolor='white')
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
self.canvas.mpl_connect('motion_notify_event', self.on_motion)
self.toolbar = NavigationToolbar(self.canvas, self.main)
self.toolbar.Realize()
self.toolbar.DeleteToolByPos(1)
self.toolbar.DeleteToolByPos(1)
self.toolbar.DeleteToolByPos(4)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
vbox.Add(self.toolbar, 0, wx.EXPAND)
self.SetSizer(vbox)
vbox.Fit(self)
def on_motion(self, event):
if self.main.thread:
return
xpos = event.xdata
ypos = event.ydata
text = ""
if xpos is not None:
spectrum = self.main.spectrum
if len(spectrum) > 0:
xpos = min(spectrum.keys(), key=lambda freq: abs(freq - xpos))
ypos = spectrum[xpos]
text = "f = {0:.3f}MHz, p = {1:.2f}dB".format(xpos, ypos)
self.main.status.SetStatusText(text, 1)
def get_canvas(self):
return self.canvas
def get_axes(self):
return self.axes
def get_toolbar(self):
return self.toolbar
示例8: CanvasFrame
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class CanvasFrame(wx.Frame):
def __init__(self, ):
wx.Frame.__init__(self, None, -1,
'CanvasFrame', size=(550, 350))
self.SetBackgroundColour(wx.NamedColour("WHITE"))
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)
self.axes.plot(t, s)
self.axes.set_xlabel('t')
self.axes.set_ylabel('sin(t)')
self.figure_canvas = FigureCanvas(self, -1, self.figure)
# Note that event is a MplEvent
self.figure_canvas.mpl_connect(
'motion_notify_event', self.UpdateStatusBar)
self.figure_canvas.Bind(wx.EVT_ENTER_WINDOW, self.ChangeCursor)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.figure_canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)
self.Fit()
self.statusBar = wx.StatusBar(self, -1)
self.statusBar.SetFieldsCount(1)
self.SetStatusBar(self.statusBar)
self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.Show()
def ChangeCursor(self, event):
self.figure_canvas.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))
def UpdateStatusBar(self, event):
if event.inaxes:
x, y = event.xdata, event.ydata
self.statusBar.SetStatusText(("x= " + str(x) +
" y=" + str(y)),
0)
示例9: CSMSectionPlot
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class CSMSectionPlot(wx.Panel):
def __init__(self, parent, coverSong1, coverSong2, CSM, idx, glplots, npplots):
wx.Panel.__init__(self, parent)
self.figure = Figure((5.0, 5.0), dpi = 100)
self.coverSong1 = coverSong1
self.coverSong2 = coverSong2
self.CSM = CSM
self.minC = np.min(CSM)
self.maxC = np.max(CSM)
self.idx = idx
self.glplots = glplots
self.npplots = npplots
self.CSMPlot = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
self.cid = self.canvas.mpl_connect('key_press_event', self.OnKeyPress)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP)
self.SetSizer(self.sizer)
self.Fit()
self.draw()
def updateIdx(self, idx):
self.idx = idx
self.coverSong1.changeBeat(self.idx[0])
self.coverSong2.changeBeat(self.idx[1])
for g in self.glplots:
g.Refresh()
for n in self.npplots:
n.draw()
self.draw()
def OnKeyPress(self, evt):
idx = self.idx
if evt.key == 'left':
idx[1] -= 1
elif evt.key == 'right':
idx[1] += 1
elif evt.key == 'up':
idx[0] -= 1
elif evt.key == 'down':
idx[0] += 1
#TODO: Bounds checking
self.updateIdx(idx)
def draw(self):
i1 = max(0, self.idx[0] - CSMNEIGHB[0])
i2 = min(self.CSM.shape[0], self.idx[0] + CSMNEIGHB[0])
j1 = max(0, self.idx[1] - CSMNEIGHB[1])
j2 = min(self.CSM.shape[1], self.idx[1] + CSMNEIGHB[1])
C = self.CSM[i1:i2+1, j1:j2+1]
self.CSMPlot.cla()
self.CSMPlot.imshow(C, cmap=matplotlib.cm.jet, interpolation = 'nearest', extent = (j1, j2, i1, i2), vmin = self.minC, vmax = self.maxC)
self.CSMPlot.hold(True)
self.CSMPlot.plot(np.array([self.idx[1]]), np.array([self.idx[0]]), 'rx')
self.canvas.draw()
示例10: _create_canvas
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
def _create_canvas(self, parent):
""" Create the MPL canvas. """
# The panel lets us add additional controls.
panel = wx.Panel(parent, -1, style=wx.CLIP_CHILDREN)
sizer = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(sizer)
# matplotlib commands to create a canvas
mpl_control = FigureCanvas(panel, -1, self.value)
try:
handle_onpick = getattr(self.object, ONPICK_HANDLER_NAME)
mpl_control.mpl_connect('pick_event', handle_onpick) #click on a point
except AttributeError:
pass
sizer.Add(mpl_control, 1, wx.LEFT | wx.TOP | wx.GROW)
toolbar = NavigationToolbar2Wx(mpl_control)
sizer.Add(toolbar, 0, wx.EXPAND)
self.value.canvas.SetMinSize((10,10))
return panel
示例11: CoverSongWaveformPlots
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class CoverSongWaveformPlots(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.parent = parent
self.figure = Figure((10.0, 1.0), dpi=100)
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)
self.Fit()
self.coverSong = None
self.cid = self.canvas.mpl_connect('button_press_event', self.onClick)
self.draw()
def updateCoverSong(self, newCoverSong):
self.coverSong = newCoverSong
if self.coverSong:
self.w = self.coverSong.waveform.flatten()
N = np.ceil( float(len(self.w)) / DOWNSAMPLEFAC) * DOWNSAMPLEFAC
w = np.zeros(N)
w[0:len(self.w)] = self.w
w = w.reshape((N/DOWNSAMPLEFAC, DOWNSAMPLEFAC))
w = np.mean(w, 1)
self.w = w
self.t = np.arange(0, N)/self.coverSong.Fs
self.t = self.t[0:-1:DOWNSAMPLEFAC]
self.y0 = np.min(self.w)
self.y1 = np.max(self.w)
self.draw()
def draw(self):
if self.coverSong:
#Plot waveform
self.axes.clear()
self.axes.plot(self.t, self.w, 'b')
self.axes.hold(True)
#Plot current marker in song
time = self.coverSong.SampleStartTimes[self.coverSong.currBeat]
self.axes.plot(np.array([time, time]), np.array([self.y0, self.y1]), 'g')
self.axes.set_title(self.coverSong.title)
self.canvas.draw()
def onClick(self, evt):
if self.parent.matching:
#If there is a matching, jump to the matched beat in the other song
self.coverSong.currBeat = self.parent.matching.getOtherIdx(self.parent.glcanvas.selectedCover.num, self.parent.glcanvas.selectedCover.currBeat)
elif self.parent.glcanvas.selectedCover:
#If there is no matching, just go to the exact same position in
#the other song
self.coverSong.currBeat = self.parent.glcanvas.selectedCover.currBeat
self.parent.glcanvas.selectedCover = self.coverSong
self.parent.updateCover()
示例12: FFTWindow
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class FFTWindow(wx.Window):
def __init__(self, *args, **kwargs):
self.window = wx.Window.__init__(self,*args,**kwargs)
self.figure=Figure()
self.x = np.linspace(-10, 20,100)
self.Y = np.sin(self.x)
self.delta_inv_x = 30/100.0
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.canvas.mpl_connect('button_press_event',self.coordPrint)
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
self.toolbar.Show()
#self.draw()
def draw(self):
self.FFTPlot = self.figure.add_subplot(111)
if len(self.FFTPlot.lines)>0:
del self.FFTPlot.lines[0]
#smooth and window the data
self.DeltaFreqY = 1/self.delta_inv_x
#padd the data
pad_mult = 10
zero_matrixY = np.zeros(len(self.Y)*pad_mult/2)
self.pad_wind_dataY = np.append(self.Y, zero_matrixY)
# pad_wind_data = np.append(zero_matrix, pad_wind_data)
self.FreqY, self.FFT_SignalY = dHvA_Util.take_fft(self.pad_wind_dataY, 20, self.DeltaFreqY)
self.FFTPlot.plot(self.FreqY,self.FFT_SignalY,linewidth=2,color='blue')
self.FFTPlot.set_xlabel('dHvA Frequency (1/T)')
self.FFTPlot.set_ylabel('Amplitude (a.u.)')
self.FFTPlot.set_title('FFT')
self.FFTPlot.relim()
self.FFTPlot.autoscale(True)
def repaint(self):
self.canvas.draw()
def coordPrint(self,e):
print "mouse clicked"
print e.xdata
print e.ydata
示例13: MatplotlibPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class MatplotlibPanel(wx.Panel):
def __init__(self,parent,ID=-1,label="",pos=wx.DefaultPosition,size=(100,25)):
self.parent = parent
#(0) Initialize panel:
wx.Panel.__init__(self,parent,ID,pos,size,wx.STATIC_BORDER,label)
self.SetMinSize(size)
#(1) Create Matplotlib figure:
self.figure = Figure(facecolor=(0.8,)*3)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self._resize()
self._create_axes()
self.cidAxisEnter = self.canvas.mpl_connect('axes_enter_event', self.callback_enter_axes)
self.cidAxisLeave = self.canvas.mpl_connect('axes_leave_event', self.callback_leave_axes)
def _create_axes(self):
self.ax = self.figure.add_axes((0,0,1,1), axisbg=[0.5]*3)
pyplot.setp(self.ax, xticks=[], yticks=[])
def _resize(self):
szPixels = tuple( self.GetClientSize() )
self.canvas.SetSize(szPixels)
szInches = float(szPixels[0])/self.figure.get_dpi() , float(szPixels[1])/self.figure.get_dpi()
self.figure.set_size_inches( szInches[0] , szInches[1] )
def callback_enter_axes(self, event):
self.parent.parent.panel_enter(event, panel=self.parent)
def callback_leave_axes(self, event):
self.parent.parent.panel_leave(event)
def cla(self):
self.ax.cla()
self.ax.set_position([0,0,1,1])
self.ax.set_axis_bgcolor([0.5]*3)
pyplot.setp(self.ax, xticks=[], yticks=[], xlim=(0,1), ylim=(0,1))
self.ax.axis('tight')
self.canvas.draw()
def plot(self, I0, I, cmax=None, pois=None):
if I!=None:
if cmax==None:
cmax = I.max()
I[I==0] = np.nan
self.ax.imshow(I, interpolation='nearest', origin='lower', vmin=0, vmax=cmax)
self.ax.contour(I0>0, 1, colors="0.5", linewidths=1)
pyplot.setp(self.ax, xticks=[], yticks=[])
self.ax.set_axis_bgcolor([0.05]*3)
self.ax.axis('image')
if pois!=None:
for i,(x,y) in enumerate(pois):
self.ax.plot(x, y, 'wo', markersize=8)
self.ax.text(x+1, y+1, '%d'%(i+1), bbox=dict(facecolor='w'))
self.canvas.draw()
示例14: MatplotlibPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
class MatplotlibPanel(wx.Panel):
def __init__(self,parent,ID=-1,label="",pos=wx.DefaultPosition,size=(100,25)):
self.parent = parent
#(0) Initialize panel:
wx.Panel.__init__(self,parent,ID,pos,size,wx.STATIC_BORDER,label)
self.SetMinSize(size)
self.parent = parent
#(1) Create Matplotlib figure:
self.figure = Figure(facecolor=(0.8,)*3)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self._resize()
self._create_axes()
self.cidAxisEnter = self.canvas.mpl_connect('axes_enter_event', self.callback_enter_axes)
self.cidAxisLeave = self.canvas.mpl_connect('axes_leave_event', self.callback_leave_axes)
#self.Bind(wx.EVT_ENTER_WINDOW, self.callback_enter_axes)
self.Bind(wx.EVT_LEAVE_WINDOW, self.callback_leave_axes)
def _create_axes(self):
self.ax = self.figure.add_axes((0,0,1,1), axisbg=[0.5]*3)
pyplot.setp(self.ax, xticks=[], yticks=[])
def _resize(self):
szPixels = tuple( self.GetClientSize() )
self.canvas.SetSize(szPixels)
szInches = float(szPixels[0])/self.figure.get_dpi() , float(szPixels[1])/self.figure.get_dpi()
self.figure.set_size_inches( szInches[0] , szInches[1] )
def callback_enter_axes(self, event):
self.parent.parent.panel_enter(event, panel=self.parent)
def callback_leave_axes(self, event):
self.parent.parent.panel_leave(event)
def cla(self):
self.ax.cla()
self.ax.set_position([0,0,1,1])
self.ax.set_axis_bgcolor([0.5]*3)
pyplot.setp(self.ax, xticks=[], yticks=[], xlim=(0,1), ylim=(0,1))
self.ax.axis('tight')
self.canvas.draw()
def plot(self, I, cmax=None):
if I!=None:
if cmax==None:
cmax = I.max()
I[I==0] = np.nan
self.ax.imshow(I, interpolation='nearest', origin='lower', vmin=0, vmax=cmax)
pyplot.setp(self.ax, xticks=[], yticks=[])
self.ax.set_axis_bgcolor([0.05]*3)
self.ax.axis('image')
self.canvas.draw()
示例15: _create_canvas
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import mpl_connect [as 别名]
def _create_canvas(self, parent):
"""
创建一个Panel, 布局采用垂直排列的BoxSizer, panel中中添加
FigureCanvas, NavigationToolbar2Wx, StaticText三个控件
FigureCanvas的鼠标移动事件调用mousemoved函数,在StaticText
显示鼠标所在的数据坐标
"""
panel = wx.Panel(parent, -1, style=wx.CLIP_CHILDREN)
def mousemoved(event):
panel.info.SetLabel("%s, %s" % (event.xdata, event.ydata))
panel.mousemoved = mousemoved
sizer = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(sizer)
mpl_control = FigureCanvas(panel, -1, self.value)
mpl_control.mpl_connect("motion_notify_event", mousemoved)
toolbar = NavigationToolbar2Wx(mpl_control)
sizer.Add(mpl_control, 1, wx.LEFT | wx.TOP | wx.GROW)
sizer.Add(toolbar, 0, wx.EXPAND|wx.RIGHT)
panel.info = wx.StaticText(parent, -1)
sizer.Add(panel.info)
self.value.canvas.SetMinSize((10,10))
return panel