本文整理汇总了Python中matplotlib.backends.backend_wx.FigureCanvasWx类的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasWx类的具体用法?Python FigureCanvasWx怎么用?Python FigureCanvasWx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FigureCanvasWx类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PlotFigure
class PlotFigure(wxFrame):
def __init__(self):
wxFrame.__init__(self, None, -1, "Test embedded wxFigure")
self.fig = Figure((5,4), 75)
self.canvas = FigureCanvasWx(self, -1, self.fig)
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
# On Windows, default frame size behaviour is incorrect
# you don't need this under Linux
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
self.toolbar.SetSize(wxSize(fw, th))
# Create a figure manager to manage things
self.figmgr = FigureManager(self.canvas, 1, self)
# Now put all into a sizer
sizer = wxBoxSizer(wxVERTICAL)
# This way of adding to sizer allows resizing
sizer.Add(self.canvas, 1, wxLEFT|wxTOP|wxGROW)
# Best to allow the toolbar to resize!
sizer.Add(self.toolbar, 0, wxGROW)
self.SetSizer(sizer)
self.Fit()
EVT_TIMER(self, TIMER_ID, self.onTimer)
def init_plot_data(self):
a = self.figmgr.add_subplot(111)
self.ind = numpy.arange(60)
tmp = []
for i in range(60):
tmp.append(numpy.sin((self.ind+i)*numpy.pi/15))
self.X = numpy.array(tmp)
self.lines = a.plot(self.X[:,0],'o')
self.count = 0
def GetToolBar(self):
# You will need to override GetToolBar if you are using an
# unmanaged toolbar in your frame
return self.toolbar
def onTimer(self, evt):
self.count += 1
if self.count >= 60: self.count = 0
self.lines[0].set_data(self.ind, self.X[:,self.count])
self.canvas.draw()
self.canvas.gui_repaint()
示例2: __init__
def __init__(self):
wxFrame.__init__(self, None, -1, "Test embedded wxFigure")
self.fig = Figure((5,4), 75)
self.canvas = FigureCanvasWx(self, -1, self.fig)
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
# On Windows, default frame size behaviour is incorrect
# you don't need this under Linux
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
self.toolbar.SetSize(wxSize(fw, th))
# Create a figure manager to manage things
self.figmgr = FigureManager(self.canvas, 1, self)
# Now put all into a sizer
sizer = wxBoxSizer(wxVERTICAL)
# This way of adding to sizer allows resizing
sizer.Add(self.canvas, 1, wxLEFT|wxTOP|wxGROW)
# Best to allow the toolbar to resize!
sizer.Add(self.toolbar, 0, wxGROW)
self.SetSizer(sizer)
self.Fit()
EVT_TIMER(self, TIMER_ID, self.onTimer)
示例3: draw_all
def draw_all(self, drawDC=None):
'''
draw everything from scratch
mostly debugging purpose
'''
print('draw_all')
self.figure.figobj.reset_axesbmp_update()
Canvas.draw(self)
示例4: CanvasFrame
class CanvasFrame(Frame):
def __init__(self):
Frame.__init__(self, None, -1,
'CanvasFrame', size=(550, 350))
self.SetBackgroundColour(NamedColor("WHITE"))
self.figure = Figure(figsize=(5, 4), dpi=100)
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.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = BoxSizer(VERTICAL)
self.sizer.Add(self.canvas, 1, TOP | LEFT | EXPAND)
# Capture the paint message
EVT_PAINT(self, self.OnPaint)
self.toolbar = MyNavigationToolbar(self.canvas, True)
self.toolbar.Realize()
if Platform == '__WXMAC__':
# Mac platform (OSX 10.3, MacPython) does not seem to cope with
# having a toolbar in a sizer. This work-around gets the buttons
# back, but at the expense of having the toolbar at the top
self.SetToolBar(self.toolbar)
else:
# On Windows platform, default window size is incorrect, so set
# toolbar width to figure width.
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version.
# As noted above, doesn't work for Mac.
self.toolbar.SetSize(Size(fw, th))
self.sizer.Add(self.toolbar, 0, LEFT | EXPAND)
# update the axes menu on the toolbar
self.toolbar.update()
self.SetSizer(self.sizer)
self.Fit()
def OnPaint(self, event):
self.canvas.draw()
event.Skip()
示例5: View
class View(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title='QRS detect')
self.SetBackgroundColour(wx.NamedColour("WHITE"))
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
#self.axes.plot(t, s)
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.add_toolbar()
def add_toolbar(self):
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
if wx.Platform == '__WXMAC__':
self.SetToolBar(self.toolbar)
else:
# On Windows platform, default window size is incorrect, so set
# toolbar width to figure width.
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version.
# As noted above, doesn't work for Mac.
self.toolbar.SetSize(wx.Size(fw, th))
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
# update the axes menu on the toolbar
self.toolbar.update()
def plot(ecg1, ecg2, marks=None):
"""
Plot will show two ECG leads, each with the marks, if available
Last row will be rr intervals
"""
if marks == None:
self.axes.plot(ecg1)
def OnPaint(self, event):
self.canvas.draw()
示例6: __init__
def __init__(self, title='', verb=1):
wx.Frame.__init__(self, None, -1, title, size=(400,300))
self.verb = verb
self.figure = Figure()
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()
# toolbar?
# self.toolbar = NavigationToolbar2Wx(self.canvas)
# self.toolbar.Realize()
# self.sizer.Add(self.toolbar, 0, wx.BOTTOM | wx.EXPAND)
# self.toolbar.update()
# axis plotting info
self.ax = None
self.xmin = 1.0
self.xmax = 0.0
self.ymin = 1.0
self.ymax = 0.0
self.xlabel = ''
self.ylabel = ''
self.style = 'graph'
self.images = []
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.update()
示例7: Plotter
class Plotter(wx.Panel):
" Simple plotter class"
def __init__(self,parent):
self.parent = parent
wx.Panel.__init__(self,parent,-1,size=(50,50))
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.figure = matplotlib.figure.Figure()
self.axPhase = self.figure.add_subplot(211)
self.axPhase.hold(False)
self.axU = self.figure.add_subplot(212)
self.axU.hold(False)
self.figure.subplots_adjust(hspace=0.5)
self.canvas = FigureCanvas(self,-1,self.figure)
self.sizer.Add(self.canvas)
self.navtoolbar = NavigationToolbar2Wx(self.canvas)
self.sizer.Add(self.navtoolbar)
self.SetSizer(self.sizer)
self.Fit()
def plotPhaseFunction(self,phasefunction):
" Plot the phase function, requires a pure function "
# create x-axis
wavelength = np.linspace(600,900,1000)
#phasefunction is dependent on frequency, not wavelength, so convert
vFun = np.vectorize(phasefunction)
phases = vFun(w2f(wavelength))
#print np.array([wavelength,phases]).transpose()
self.axPhase.plot(wavelength,phases)
self.axPhase.set_xlabel("Wavelength [nm]")
self.axPhase.set_ylabel("Phase [rad]")
self.canvas.draw()
def plotVoltages(self,phasefunction):
" Plot the voltages as a function of pixel index "
# create x-axis
x = np.arange(640)
# get the data: do apply_phase with simulateOnly=True
print " PATTERN"
pattern = self.parent.slmCal.apply_phase_on_freq(phasefunction,simulateOnly=True)
self.axU.plot(x,pattern,'-x')
self.axU.set_xlabel("Pixel index #")
self.axU.set_ylabel("Voltage")
self.canvas.draw()
示例8: __init__
def __init__(self, parent):
wx.Frame.__init__(self, parent, title='QRS detect')
self.SetBackgroundColour(wx.NamedColour("WHITE"))
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
#self.axes.plot(t, s)
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.add_toolbar()
示例9: __init__
def __init__(self,parent):
self.parent = parent
wx.Panel.__init__(self,parent,-1,size=(50,50))
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.figure = matplotlib.figure.Figure()
self.axPhase = self.figure.add_subplot(211)
self.axPhase.hold(False)
self.axU = self.figure.add_subplot(212)
self.axU.hold(False)
self.figure.subplots_adjust(hspace=0.5)
self.canvas = FigureCanvas(self,-1,self.figure)
self.sizer.Add(self.canvas)
self.navtoolbar = NavigationToolbar2Wx(self.canvas)
self.sizer.Add(self.navtoolbar)
self.SetSizer(self.sizer)
self.Fit()
示例10: __init__
def __init__(self, title='', as_one=0, verb=1):
wx.Frame.__init__(self, None, -1, title, size=(400,300))
self.verb = verb
self.figure = Figure()
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.canvas.mpl_connect('key_press_event', self.cb_keypress)
self.as_one = as_one
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.update()
示例11: __init__
def __init__(self, parent):
wx.Frame.__init__(self, parent, title='QRS detect')
self.SetBackgroundColour(wx.NamedColour("WHITE"))
self.figure = Figure()
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.add_toolbar()
# http://stackoverflow.com/questions/4740988/add-new-navigate-modes-in-matplotlib
self.pan_tool = self.toolbar.FindById(
self.toolbar._NTB2_PAN)
self.zoom_tool = self.toolbar.FindById(
self.toolbar._NTB2_ZOOM)
示例12: CanvasFrame
class CanvasFrame(wx.Frame):
"""create a main plotting canvas
title : optional window title
verb : verbose level (default 1)
"""
counter = 0
def __init__(self, title='', verb=1):
wx.Frame.__init__(self, None, -1, title, size=(400,300))
self.verb = verb
self.figure = Figure()
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()
# toolbar?
# self.toolbar = NavigationToolbar2Wx(self.canvas)
# self.toolbar.Realize()
# self.sizer.Add(self.toolbar, 0, wx.BOTTOM | wx.EXPAND)
# self.toolbar.update()
# axis plotting info
self.ax = None
self.xmin = 1.0
self.xmax = 0.0
self.ymin = 1.0
self.ymax = 0.0
self.xlabel = ''
self.ylabel = ''
self.style = 'graph'
self.images = []
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.update()
def cb_keypress(self, event):
if event.key == 'q':
self.Close()
def set_limits(self, xmin=1.0, xmax=0.0, ymin=1.0, ymax=0.0):
"""if xmin < xmax: apply, and similarly for y"""
if xmin < xmax:
self.xmin = xmin
self.xmax = xmax
if self.verb > 2: print '-- resetting xlimits to:', xmin, xmax
if ymin < ymax:
self.ymin = ymin
self.ymax = ymax
if self.verb > 2: print '-- resetting ylimits to:', ymin, ymax
def plot_data(self, data, title=''):
"""plot data
style can be 'graph' or 'bar'"""
if self.ax == None:
self.ax = self.figure.add_subplot(1,1,1,title=title)
self.ax.clear()
if self.style == 'graph':
self.ax.plot(data)
self.ax.grid(True)
else: # bars of width 1
offsets = N.arange(len(data))
bars = self.ax.bar(offsets, data, 1)
self.ax.set_xlabel(self.xlabel)
self.ax.set_ylabel(self.ylabel)
# after data is plotted, set limits
if self.xmin < self.xmax: self.ax.set_xlim((self.xmin, self.xmax))
if self.ymin < self.ymax: self.ax.set_ylim((self.ymin, self.ymax))
self.Fit() # maybe not applied without a running app loop
self.canvas.draw()
def exit(self):
self.Destroy()
示例13: __init__
def __init__(self, *args, **kargs):
Canvas.__init__(self, *args, **kargs)
CanvasMod.__init__(self, *args, **kargs)
示例14: CanvasFrame
class CanvasFrame(wx.Frame):
"""create a main plotting canvas
title : optional window title
as_one : plot as one overlapping graph
(else a list of scaled graphs)
verb : verbose level (default 1)
"""
counter = 0
def __init__(self, title="", as_one=0, verb=1):
wx.Frame.__init__(self, None, -1, title, size=(400, 300))
self.counter += 1
self.verb = verb
self.figure = Figure()
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.canvas.mpl_connect("key_press_event", self.cb_keypress)
self.as_one = as_one
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.update()
def cb_keypress(self, event):
if event.key == "q":
self.Close()
def plot_scaled_mat(self, amat, verb=1):
"""plot data scaled and shifted to fit on one graph
data - AfniMatrix, list of float lists, or 1D file
title - optional window title
verb - optional verbose level
"""
# allow matlist, list of float lists,
# if type(matlist) == type([]):
# e0 = matlist[0]
# if type
if not matlist:
return
nmats = len(matlist)
if nmats < 1:
return
yformat = FormatStrFormatter("%5.1f")
def plot_matlist(self, matlist, title="", ylabels=[], ftcolors=0, verb=1):
"""plot AfniMatrix list, one graph per AfniMatrix
matlist - list of AfniMatrix elements
title - optional window title
ylabels - optional list of ylabel per mat
ftcolors - flag: use fit/timeseries colors (black blue)
verb - optional verbose level
"""
if not matlist:
return
nmats = len(matlist)
if nmats < 1:
return
yformat = FormatStrFormatter("%5.1f")
matplotlib.rcParams["lines.linewidth"] = 2
# make a label list, and get max length (among any label[0])
if ylabels:
labels = ylabels
else:
labels = []
rlen = 0
nruns = 0
maxlen = 0
for ind in range(nmats):
if ylabels:
lab = ylabels[ind]
else:
if matlist[ind].labels:
lab = matlist[ind].labels[0]
else:
lab = ""
labels.append(lab)
if len(lab) > maxlen:
maxlen = len(lab)
# note run info
if nruns == 0 and matlist[ind].nruns > 1:
nruns = matlist[ind].nruns
rlen = matlist[ind].run_len
for ind in range(nmats):
amat = matlist[ind]
#.........这里部分代码省略.........
示例15: View
class View(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title='QRS detect')
self.SetBackgroundColour(wx.NamedColour("WHITE"))
self.figure = Figure()
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.add_toolbar()
# http://stackoverflow.com/questions/4740988/add-new-navigate-modes-in-matplotlib
self.pan_tool = self.toolbar.FindById(
self.toolbar._NTB2_PAN)
self.zoom_tool = self.toolbar.FindById(
self.toolbar._NTB2_ZOOM)
def add_toolbar(self):
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
if wx.Platform == '__WXMAC__':
self.SetToolBar(self.toolbar)
else:
# On Windows platform, default window size is incorrect, so set
# toolbar width to figure width.
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version.
# As noted above, doesn't work for Mac.
self.toolbar.SetSize(wx.Size(fw, th))
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
# update the axes menu on the toolbar
self.toolbar.update()
def init_plot(self, ecg1, ecg2, marks):
"""
Plot will show two ECG leads, each with the marks, if available
Last row will be rr intervals
"""
ecg1 += (ecg2.max() - ecg2.min())
self.axes.plot(ecg1, 'b')
self.axes.plot(ecg2, 'b')
if marks != None:
for samp, label in marks:
self.axes.plot(samp, ecg1[samp], 'ok')
self.axes.plot(samp, ecg2[samp], 'ok')
def add_mark(self, x, y1, y2):
"""
New mark to be plotted.
y1 and y2 are heights for lead1 and lead2
"""
self.axes.plot(x, y1, 'ok')
self.axes.plot(x, y2, 'ok')
self.canvas.draw()
def remove_mark(self, x, y1, y2):
"""
Remove existing marks from leads 1 and 2
Draw red cross over to denote remove
"""
print 'plotting at', x, y1
self.axes.plot(x, y1, 'xr')
self.axes.plot(x, y2, 'xr')
self.canvas.draw()
def _get_xrange(self):
xmin, xmax = self.axes.get_xbound()
return xmax - xmin
def OnPaint(self, event):
self.canvas.draw()