本文整理汇总了Python中matplotlib.backends.backend_wxagg.FigureCanvasWxAgg.draw方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasWxAgg.draw方法的具体用法?Python FigureCanvasWxAgg.draw怎么用?Python FigureCanvasWxAgg.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_wxagg.FigureCanvasWxAgg
的用法示例。
在下文中一共展示了FigureCanvasWxAgg.draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wxMatplotPanelSimple
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class wxMatplotPanelSimple( wx.Panel ):
def __init__( self, renderPanel, color=None, dpi=None, **kwargs ):
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
# initialize Panel
if 'id' not in list(kwargs.keys()):
kwargs['id'] = wx.ID_ANY
if 'style' not in list(kwargs.keys()):
kwargs['style'] = wx.NO_FULL_REPAINT_ON_RESIZE
wx.Panel.__init__( self, renderPanel, **kwargs )
self.figure = Figure( None, dpi )
#self.canvas = NoRepaintCanvas( self, -1, self.figure )
self.canvas = FigureCanvasWxAgg( self, -1, self.figure )
sizer = wx.BoxSizer();
sizer.Add( self.canvas, 1, wx.EXPAND )
self.SetSizer( sizer )
self.axes = self.figure.add_subplot( 111 )
self.axes.set_aspect( 'auto' )
self.Bind(wx.EVT_SIZE, self._onSize)
def _onSize( self, event = None ):
pixels = tuple( [ self.GetSize()[0], self.GetSize()[1] ] )
print(pixels)
#if self.canvas.GetMinSize( )[0] != pixels[0] or \
#self.canvas.GetMinSize( )[1] != pixels[1] :
self.canvas.SetMinSize( pixels )
self.figure.set_size_inches( float( pixels[ 0 ] )/self.figure.get_dpi(),
float( pixels[ 1 ] )/self.figure.get_dpi() )
self.canvas.draw()
示例2: PlotFigure
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class PlotFigure(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, title="Sensor Monitor", size=(800, 600))
#set window size
self.fig = Figure((8, 6), 100)
self.canvas = FigureCanvas(self, wx.ID_ANY, self.fig)
self.ax = self.fig.add_subplot(111)
self.ax.set_ylim([0, 100])
self.ax.set_xlim([0, POINTS])
self.ax.set_autoscale_on(False)
self.ax.set_xticks([])
self.ax.set_yticks(range(0, 101, 10))
self.ax.grid(True)
self.user = [None] * POINTS
self.l_user,=self.ax.plot(range(POINTS),self.user,label='Light Sensors')
self.ax.legend(loc='upper center',
ncol=4,
prop=font_manager.FontProperties(size=10))
self.canvas.draw()
self.bg = self.canvas.copy_from_bbox(self.ax.bbox)
wx.EVT_TIMER(self, TIMER_ID, self.onTimer)
def onTimer(self, evt):
self.canvas.restore_region(self.bg)
for i in range(0,240):
index = int(i/40)*40
per = (index-i)+20.0
per =((math.sin((per/20.0)*math.pi/2))+1.0)/2.0
self.user[i+30] = 100-(float(arr[i/40])*per+float(arr[(i+40)/40])*(1-per))*1
self.l_user.set_ydata(self.user)
self.ax.draw_artist(self.l_user)
self.canvas.blit(self.ax.bbox)
示例3: GraphPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class GraphPanel(wx.Panel):
def __init__(self, parent, streamValuesHistory):
wx.Panel.__init__(self, parent)
self._streamValuesHistory = streamValuesHistory
self.figure = Figure()
self.figure.patch.set_facecolor('black')
self.axes = self.figure.add_axes([0.1, 0.025, 0.9, 0.95])
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._colors = [(0.0, 1.0, 0.0), (1.0, 0.0, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 1.0), (0.0, 0.0, 1.0), (1.0, 0.0, 1.0)]
def UpdateGraphs(self):
self.axes.clear()
self.axes.patch.set_facecolor((0, 0, 0))
self.axes.grid(b=True, color=(0, 0.1, 0), which='major', linestyle='-', linewidth=1)
self.axes.yaxis.set_tick_params(labelcolor=(0.6, 0.6, 0.6))
self.axes.set_axisbelow(True)
"""Draw data."""
iColor = 0
for streamValues in self._streamValuesHistory.itervalues():
valuesNumber = int(self.axes.get_window_extent().width)
X = range(0, valuesNumber)
Y = [streamValues[-min(valuesNumber, len(streamValues))]] * (valuesNumber - len(streamValues)) + streamValues[-valuesNumber:]
self.axes.plot( X, Y, color=self._colors[iColor%len(self._colors)], linewidth=1)
iColor+=1
self.canvas.draw()
示例4: rightButtonUp
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
def rightButtonUp(self, evt, x, y):
"""
Completely overrides base class functionality.
"""
view = self.getView()
if self.selectedAxes is None:
axes, xdata, ydata = self.find_axes(view, x, y)
else:
axes = self.selectedAxes
xdata, ydata = get_data(axes, x, y)
self.setActiveSubplot(axes)
if self.zoomEnabled and self.rightClickUnzoom:
xmin = xmax = None
for axes in self.find_all_axes(view, x, y): # unzoom all axes
self.limits.restore(axes)
if not self.limits.can_unzoom(axes):
# rescale manually - wxmpl will try to autoscale
if xmin is None or xmax is None: # make sure x-axis matches
xmin, xmax = axes.viewLim.intervalx().get_bounds()
axes.set_xlim(xmin, xmax)
axes._send_xlim_event()
view.crosshairs.clear()
view.draw()
view.crosshairs.set(x, y)
if self.IsInfoMode() and axes is not None:
self.DisplayAllSubplots()
FigureCanvasWxAgg.draw(view)
if self.IsPanMode() and axes is not None:
self.panTool.end_pan_all(x, y, self.find_all_axes(view, x, y))
示例5: PlotPanel2
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class PlotPanel2(wx.Panel):
def __init__(self, parent, **kwargs):
wx.Panel.__init__(self, parent, **kwargs)
self.figure = mpl.figure.Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(self.canvas, 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER)
self.SetSizer(self.sizer)
self.Fit()
def Draw(self):
global XSlice, YSlice, SSlice, DataSlice
self.axes.cla()
XSlice = np.linspace(coord1.x,coord2.x,200)
YSlice = np.linspace(coord1.y,coord2.y,200)
self.localdx = XSlice[1] - XSlice[0]
self.localdy = YSlice[1] - YSlice[0]
self.localds = np.sqrt(self.localdx**2 + self.localdy**2)
SSlice = [self.localds*x for x in range(200)]
DataSlice = []
for x,y in zip(XSlice,YSlice):
DataSlice.append(DataFit(x,y))
self.axes.plot(SSlice,DataSlice)
self.canvas.draw()
示例6: rightButtonUp
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
def rightButtonUp(self, evt, x, y):
"""
Completely overrides base class functionality.
"""
view = self.getView()
if self.selectedAxes is None:
axes, xdata, ydata = wxmpl.find_axes(view, x, y)
else:
axes = self.selectedAxes
xdata, ydata = get_data(axes, x, y)
self.setActiveSubplot(axes)
if (axes is not None and self.zoomEnabled and self.rightClickUnzoom
and self.limits.restore(axes)):
view.crosshairs.clear()
view.draw()
view.crosshairs.set(x, y)
if self.IsInfoMode() and axes is not None:
self.DisplayAllSubplots()
FigureCanvasWxAgg.draw(view)
if self.IsPanMode() and axes is not None:
self.panTool.end_pan(x, y, axes)
示例7: panAll
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
def panAll(self, x, y, axesList):
"""
Pans across multiple subplots simultaneously. Use this
function rather than pan to avoid lag on the x-axis.
"""
if not self.enabled: return
i=0
movex, movey = 0, 0
xmin, xmax = 0, 0
for axes in axesList:
if not is_log_x(axes):
xtick = axes.get_xaxis()._get_tick(major=False)._size
movex = (self.getX() - x) / xtick / 10
# TBF: matplotlib's Axes' panx method is broken, so we do it here
axes.xaxis.pan(movex)
if i==0: # we want to keep all plots on a common x-axis
xmin, xmax = axes.viewLim.intervalx().get_bounds()
axes.set_xlim(xmin, xmax)
axes._send_xlim_event()
if not is_log_y(axes):
ytick = axes.get_yaxis()._get_tick(major=False)._size
movey = (self.getY() - y) / ytick / 10
axes.pany(movey)
i += 1
self.panx += movex
self.pany += movey
self.setX(x)
self.setY(y)
FigureCanvasWxAgg.draw(self.getView())
示例8: CapacityPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class CapacityPanel(MyPanel):
def __init__(self, *args, **kwargs):
MyPanel.__init__(self, *args, **kwargs)
self.vbox = wx.BoxSizer(wx.VERTICAL)
fig = Figure(facecolor=self.face_col)
self.ax = fig.add_subplot(111)
self.canvas = FigureCanvas(self, -1, fig)
self.vbox.Add(self.canvas, flag = wx.EXPAND | wx.ALL)
self.SetSizerAndFit(self.vbox)
pub.subscribe(self.redraw, "assignments_calced")
def redraw(self, message):
"""Create a histogram"""
e_caps = self.model.excessCap()
e_caps = [x * 100 for x in e_caps]
self.ax.clear()
n, bins, patches = self.ax.hist(e_caps, normed=False, bins=10, color="cornflowerblue",
rwidth=.8, linewidth=0)
self.ax.set_xlabel("Excess Capacity (%)")
self.ax.set_ylabel("No. of Courses")
self.ax.set_title("Distribution of Excess Capacity")
num_courses = float(len(e_caps))
s_labels = [ 100 * p.get_height()/num_courses for p in patches]
s_labels = [ "%.0f%%" % p for p in s_labels]
self.labelBars(patches, s_labels, self.ax)
self.canvas.draw()
示例9: BarsFrame
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class BarsFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.data = [5, 6, 9, 14]
self.create_main_panel()
self.draw_figure()
def create_main_panel(self):
self.panel = wx.Panel(self)
self.fig = Figure((5.0, 4.0))
self.canvas = FigCanvas(self.panel, -1, self.fig)
self.axes = self.fig.add_subplot(111)
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.vbox.Add(self.canvas)
self.panel.SetSizer(self.vbox)
self.vbox.Fit(self)
def draw_figure(self):
x = range(len(self.data))
self.axes.clear()
self.axes.bar(left=x, height=self.data)
self.canvas.draw()
def on_exit(self, event):
self.Destroy()
示例10: PageThree
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class PageThree(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.figure = Figure(dpi=50)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
self.plotLast = wx.Button(self,-1,label="Plot Last")
self.Bind(wx.EVT_BUTTON, self.plotLastButtonClick, self.plotLast)
topSizer = wx.BoxSizer(wx.HORIZONTAL)
sizer = wx.BoxSizer(wx.VERTICAL)
topSizer.Add(self.plotLast, 0, wxFIXED_MINSIZE)
topSizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
sizer.Add(topSizer,1,wx.GROW)
sizer.Add(self.toolbar, 0, wx.GROW)
self.SetSizer(sizer)
self.Fit()
def plotLastButtonClick(self, evt):
gh.plotGraph(self.figure)
self.canvas.draw()
示例11: Plot
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class Plot(wx.Panel):
def __init__(self, parent, dpi=None, **kwargs):
wx.Panel.__init__(self, parent, **kwargs)
self.figure = mpl.figure.Figure(dpi=dpi, figsize=(2, 2))
self.canvas = Canvas(self, wx.ID_ANY, self.figure)
self.check = wx.CheckBox(self, wx.ID_ANY, "Show contour")
self.Bind(wx.EVT_CHECKBOX, self.OnChange, self.check)
self.distMod = SinModulator(self, 'Amplitude modulator', cycles=(2,100), phase=(0, 999))
self.Bind(EVT_UPDATE_EVENT, self.OnChange, self.distMod)
sizerV = wx.BoxSizer(wx.VERTICAL)
sizerV.Add(self.distMod)
sizerV.Add(self.check, 0, wx.EXPAND)
sizerH = wx.BoxSizer(wx.HORIZONTAL)
sizerH.Add(self.canvas, 0, wx.SHAPED | wx.EXPAND)
sizerH.Add(sizerV)
self.SetSizer(sizerH)
self.width, self.height = 256, 256
def CalcPixel(self, i, j):
x = 2.0 * i / self.width - 1.0
y = 2.0 * j / self.height - 1.0
dist = np.sqrt(x**2 + y**2)
angle = np.arctan2(y, x)
data = self.distMod
if data.active:
phase = data.phase * 2.0 * np.pi
newAngle = angle * data.cycles + phase
distDiff = np.cos(newAngle) * dist / data.cycles
else:
distDiff = 0.0
return 1.0 - (dist + distDiff)
def Draw(self):
self.figure.clear()
subplot = self.figure.add_subplot(111)
x = np.arange(0.0, self.width, 1.0)
y = np.arange(0.0, self.height, 1.0)
I, J = np.meshgrid(x, y)
C = np.clip(self.CalcPixel(I, J), 0.0, 1.0)
if self.check.IsChecked():
self.CS = subplot.contour(I, J, C)
subplot.clabel(self.CS, inline=0.1, fontsize=8)
im = subplot.imshow(C, cmap=cm.gray)
im.set_interpolation('bilinear')
def OnChange(self, _):
self.Draw()
self.canvas.draw()
示例12: CanvasPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class CanvasPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
self.toolbar = Toolbar(self.canvas) #matplotlib toolbar
self.toolbar.Realize()
self.sizer = wx.BoxSizer(wx.VERTICAL)
#self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.sizer.Add(self.canvas, 1, wx.EXPAND | wx.ALL)
# Best to allow the toolbar to resize!
self.sizer.Add(self.toolbar, 0, wx.GROW)
self.SetSizer(self.sizer)
self.Fit()
def GetToolBar(self):
# You will need to override GetToolBar if you are using an
# unmanaged toolbar in your frame
return self.toolbar
def draw(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)
self.axes.plot(t, s)
def OnPaint(self, event):
self.canvas.draw()
示例13: MPLPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class MPLPanel(wx.Panel):
def __init__(self, *args, **kwargs):
super(MPLPanel, self).__init__(*args, **kwargs)
# Setup the canvas
self.dpi = 100
self.fig = Figure((3.0, 2.0), dpi=self.dpi)
self.canvas = FigCanvas(self, -1, self.fig)
self.plot_dict = None
# Setup the toolbar/statustextctrl
self.toolbar = NavigationToolbar(self.canvas)
self.toolbar.AddSeparator()
self.statusctrl = wx.StaticText(self.toolbar, style=wx.TE_READONLY, \
size=wx.Size(300,25))
self.toolbar.AddControl(self.statusctrl)
# Do the layout
panelvbox = wx.BoxSizer(wx.VERTICAL)
panelvbox.Add(self.canvas, 1, flag=wx.EXPAND|wx.GROW|wx.ALL)
panelvbox.Add(self.toolbar, 0, flag=wx.EXPAND|wx.GROW|wx.ALL)
self.SetSizer(panelvbox)
panelvbox.Fit(self)
self.canvas.draw()
def add_plot_line(self, data, label):
if self.ax is None:
self.ax = self.fig.add_subplot(111)
else:
self.plot_dict[label] = self.ax.plot(data)
self.canvas.draw()
def clear_plot(self):
self.ax.clear()
示例14: CanvasFrame
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class CanvasFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
'CanvasFrame', size=(550, 350))
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 = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND)
# Capture the paint message
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.toolbar = MyNavigationToolbar(self.canvas, True)
self.toolbar.Realize()
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version.
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.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()
示例15: GraphPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import draw [as 别名]
class GraphPanel(wx.Panel):
def __init__(self,parent):
wx.Panel.__init__(self,parent)
self.SetBackgroundColour('#FFFFFF')
self.quote = wx.StaticText(self,label = "GRAPH PANEL", pos = (200,10))
self.figure = Figure(dpi=100,figsize=(5,8))
self.axes = self.figure.add_subplot(111)
self.axes.axis([0,1,0,60])
self.axes.set_ylabel('time (s)')
green = self.axes.axhline(y=-1,color='g',lw=4)
blue = self.axes.axhline(y=-1,color='b',lw=4)
red = self.axes.axhline(y=-1,color='r',lw=4)
self.axes.legend((green,blue,red),("Tone","Level Press","Reward"),loc="upper right")
self.canvas = FigureCanvas(self, -1, self.figure)
wx.EVT_PAINT(self, self.OnPaint)
def OnPaint(self, event):
self.canvas.draw()
event.Skip()
def OnSetFocus(self, event):
#self.color = '#0099f7'
self.color = 'yellow'
self.Refresh()
def OnKillFocus(self, event):
self.color = '#b3b3b3'
self.Refresh()