本文整理汇总了Python中matplotlib.backends.backend_wxagg.FigureCanvasWxAgg.gui_repaint方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasWxAgg.gui_repaint方法的具体用法?Python FigureCanvasWxAgg.gui_repaint怎么用?Python FigureCanvasWxAgg.gui_repaint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_wxagg.FigureCanvasWxAgg
的用法示例。
在下文中一共展示了FigureCanvasWxAgg.gui_repaint方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NaoPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import gui_repaint [as 别名]
class NaoPanel(wx.Panel):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Panel.__init__(self, id=wxID_LEFTPANEL, name='NaoPanel',
parent=prnt, pos=wx.Point(208, 8), size=wx.Size(800, 400),
style=wx.NO_BORDER | wx.TAB_TRAVERSAL)
self.SetClientSize(wx.Size(800, 400))
self.SetBackgroundColour(wx.Colour(0, 0, 255))
self.Bind(wx.EVT_PAINT, self.OnNaoPanelPaint)
def __init__(self, parent, id, pos, size, style, name):
self._init_ctrls(parent)
##Create a matplotlib figure/canvas in this panel
##the background colour will be the same as the panel
##the size will also be the same as the panel
##calculate size in inches
pixels_width,pixels_height = self.GetSizeTuple()
self.dpi = 96.0
inches_width = pixels_width/self.dpi
inches_height = pixels_height/self.dpi
##calculate colour in RGB 0 to 1
colour = self.GetBackgroundColour()
self.fig = Figure(figsize=(inches_width,inches_height), dpi = self.dpi\
,facecolor=(colour.Red()/255.0, colour.Green()/255.0, colour.Blue()/255.0)\
,edgecolor=(colour.Red()/255.0, colour.Green()/255.0, colour.Blue()/255.0))
##left : the left side of the subplots of the figure
## | right : the right side of the subplots of the figure
## | bottom : the bottom of the subplots of the figure
## | top : the top of the subplots of the figure
## | wspace : the amount of width reserved for blank space between subplots
## | hspace : the amount of height reserved for white space between subplots
## |
self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
##now put everything in a sizer
sizer = wx.BoxSizer(wx.VERTICAL)
# This way of adding to sizer allows resizing
sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
self.SetSizer(sizer)
self.Fit()
##now finally create the actual plot
##self.axes = self.fig.add_subplot(111)
self.axes = self.fig.add_axes((0.08,0.08,0.90,0.85)) ##left,bottom,width,height
self.naohistoryplot = self.axes.plot([0,0],[0,0], 'r', animated=True)
self.naohistoryx = list()
self.naohistoryy = list()
self.positionmeasurementplot = self.axes.plot([0,0],[0,0], 'blue', marker='o', markersize=5, linewidth=0, markeredgewidth=0, animated=True)
self.orientationmeasurementplot = self.axes.plot([0,0],[0,0], 'blue', linewidth=2, animated=True)
self.shapeplot = self.axes.plot([0,0],[0,0], 'blue', marker='o', markersize=2, linewidth=0, markeredgewidth=0, animated=True)
self.estimateplot = self.axes.plot([0,0],[0,0], 'red', linewidth=2, animated=True)
self.particleplot = self.axes.quiver([0,0],[0,0], [1,1], [0.5, -0.5], [1, 1], cmap=pylab.gray(), animated=True)
##plot formatting
self.axes.set_title('Nao Image', fontsize='10')
self.axes.set_xlabel('y (cm)', fontsize='10')
self.axes.set_ylabel('x (cm)', fontsize='10')
ticks = numpy.arange(-25, 25 + 5, 5)
labels = [str(tick) for tick in ticks]
self.axes.set_yticks(ticks)
self.axes.set_yticklabels(labels, fontsize=8)
self.axes.set_ylim(ticks[0], ticks[-1])
ticks = -numpy.arange(-50, 50+5, 5)
labels = [str(tick) for tick in ticks]
self.axes.set_xticks(ticks)
self.axes.set_xticklabels(labels,fontsize=8)
self.axes.set_xlim(ticks[0], ticks[-1])
self.canvas.draw()
self.canvas.gui_repaint()
# save the clean slate background -- everything but the animated line
# is drawn and saved in the pixel buffer background
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
#self.leftedgeplot = self.axes.plot([0,0],[0,0], 'orange', marker='o', markersize=4, linewidth=0, animated=True)
#self.rightedgeplot = self.axes.plot([0,0],[0,0], 'purple', marker='o', markersize=4, linewidth=0, animated=True)
def setNaoFinder(self, finder):
""" """
self.NAOFinder = finder
def setLocalisation(self, localisation):
""" """
self.Localisation = localisation
def updateData(self, data):
"""updateData. Updates the data that this panel is displaying.
"""
# Note the x values are plotted on the y-axis, and the y values are plotted on the x-axis
naox = self.Localisation.X
naoy = self.Localisation.Y
naoorientation = self.Localisation.Orientation
measurednaox = self.NAOFinder.NaoX
measurednaoy = self.NAOFinder.NaoY
#.........这里部分代码省略.........
示例2: Plotter
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import gui_repaint [as 别名]
class Plotter():
def __init__(self, parent):
""" create the figure and canvas to be redrawn and initialize plotting parameters """
self.parentPanel = parent
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.figure.subplots_adjust(bottom = 0.25)
self.canvas = FigureCanvas(self.parentPanel, -1, self.figure)
self.xvalues = []
self.yvalues = []
self.ybuffer = []
self.timeaxis = []
# y-axis range (in mV)
self.ymax = 1.5
self.ymin = -0.5
# count the number of ECG samples received
self.samples_counter = 0
self.ysamples_counter = 0
self.setTicks()
def setTicks(self):
""" set x and y axes major and minor tick locators, formatters and labels """
# define tick locators
self.xMajor = LinearLocator(numticks = 16)
self.xMinor = LinearLocator(numticks = 76)
self.yMajor = LinearLocator(numticks = 5)
self.yMinor = LinearLocator(numticks = 17)
self.starttime = datetime.datetime.today()
self.starttime_tick = time.mktime(self.starttime.timetuple())
self.currenttime = self.starttime + datetime.timedelta(seconds = 3)
self.currenttime_tick = time.mktime(self.currenttime.timetuple())
self.lines = self.axes.plot([self.starttime], [0], 'r-')
# set tick locators
self.axes.xaxis.set_major_locator(self.xMajor)
self.axes.xaxis.set_minor_locator(self.xMinor)
self.axes.yaxis.set_major_locator(self.yMajor)
self.axes.yaxis.set_minor_locator(self.yMinor)
self.axes.set_xlim((date2num(self.starttime),date2num(self.currenttime)))
# create x-axis tick labels (seconds)
self.axes.xaxis.set_ticklabels(self.createXTickLabels(self.currenttime_tick), rotation = 30, ha = "right", size = 'smaller', name = 'Calibri')
self.axes.set_ylim(self.ymin,self.ymax)
# create y-axis tick labels (mV)
self.axes.yaxis.set_ticklabels(self.createYTickLabels(self.ymin), size = 'smaller', name = 'Calibri')
# set the properties of the minor axes
self.axes.grid(color = 'lightgrey', linewidth = 0.05, linestyle = ':', which = 'minor')
# set the properties of the major axes
self.axes.grid(color = 'slategrey', linewidth = 0.5, linestyle = '-', which = 'major')
def clearPlot(self):
""" clears the plotter """
# clear all the contents of the x-axis, y-axis and time-value arrays
self.xvalues = []
self.yvalues = []
self.ybuffer = []
self.timeaxis = []
# set the position of the slider to its initial position
self.time_scroller.reset()
self.time_scroller.disconnect(self.time_scroller.on_changed(self.updateWindow))
# re-initialize y-axis limits
self.ymax = 2
self.ymin = -4
# re-initialize number of samples plotted
self.samples_counter = 0
self.ysamples_counter = 0
# redraw the canvas to plot null data
self.lines[0].set_data([0], [0])
self.canvas.draw()
self.canvas.gui_repaint()
def initPlot(self):
""" redraw the canvas to set the initial x and y axes when plotting starts """
# set the reference time of plotting
self.starttime = datetime.datetime.today()
self.starttime_tick = time.mktime(self.starttime.timetuple())
# set the current time of plotting (located at the end point of the plotter window)
self.currenttime = self.starttime + datetime.timedelta(seconds = 3)
self.currenttime_tick = time.mktime(self.currenttime.timetuple())
# set the time-value array for 15-second (equivalent to a duration of 1 EDF file)
self.endtime = self.starttime + datetime.timedelta(seconds = 15)
#.........这里部分代码省略.........
示例3: AvoPlotFigure
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import gui_repaint [as 别名]
#.........这里部分代码省略.........
"""
return self._mpl_figure
def on_mouse_button(self,evnt):
"""
Event handler for mouse click events in the figure canvas.
"""
#if the zoom tools are active, then skip the event
if self._is_panned or self._is_zoomed:
return
#otherwise find out what subplot it occurred in and pass the event over
for subplot in self.get_child_elements():
subplot.on_mouse_button(evnt)
def set_status_bar(self, statbar):
"""
Associates a status bar with this figure.
"""
self.tb.set_status_bar(statbar)
def set_subplot_layout_basic(self, positions):
"""
Not yet implemented!
positions = {name1:(row, col),name2:(row,col)}
"""
raise NotImplementedError
def go_home(self):
"""
Returns all subplots within the figure to their default zoom level.
"""
#return all the subplots to their default (home) zoom level
for s in self.get_child_elements():
ax = s.get_mpl_axes()
ax.relim()
ax.autoscale(enable=True)
ax.autoscale_view()
#show the changes
self.canvas.draw()
self.canvas.gui_repaint()
def zoom(self):
"""
Toggles the zoom functionality for the figure.
"""
self._is_panned = False
self._is_zoomed = not self._is_zoomed
self.tb.zoom()
def back(self):
"""
Returns the figure to its previous view.
"""
self.tb.back()
def forward(self):
"""
Returns the figure to its next view.
"""
self.tb.forward()
def pan(self):
"""
Toggles the pan/zoom functionality for the figure.
"""
self._is_zoomed = False
self._is_panned = not self._is_panned
self.tb.pan()
def clear_zoom_history(self):
"""
Clears the zoom history - therefore disabling the zoom buttons.
"""
if self.tb is not None:
self.tb._views._elements = []
self.tb._views._pos = 0
wx.GetApp().GetTopWindow().toolbar.update_history_buttons()
def save_figure_as_image(self):
"""
Opens a file save dialog for exporting the figure to an image file - all
matplotlib output formats are supported.
"""
try:
self.tb.save_figure(None)
except NotImplementedError:
self.tb.save(None)
示例4: CartesianPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import gui_repaint [as 别名]
class CartesianPanel(wx.Panel):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Panel.__init__(self, id=wxID_LEFTPANEL, name='CartesianPanel',
parent=prnt, pos=wx.Point(8, 8), size=wx.Size(200, 400),
style=wx.NO_BORDER | wx.TAB_TRAVERSAL)
self.SetClientSize(wx.Size(200, 400))
self.SetBackgroundColour(wx.Colour(0, 0, 255))
self.Bind(wx.EVT_PAINT, self.OnCartesianPanelPaint)
def __init__(self, parent, id, pos, size, style, name):
self._init_ctrls(parent)
##Create a matplotlib figure/canvas in this panel
##the background colour will be the same as the panel
##the size will also be the same as the panel
##calculate size in inches
pixels_width,pixels_height = self.GetSizeTuple()
self.dpi = 96.0
inches_width = pixels_width/self.dpi
inches_height = pixels_height/self.dpi
##calculate colour in RGB 0 to 1
colour = self.GetBackgroundColour()
self.fig = Figure(figsize=(inches_width,inches_height), dpi = self.dpi\
,facecolor=(colour.Red()/255.0, colour.Green()/255.0, colour.Blue()/255.0)\
,edgecolor=(colour.Red()/255.0, colour.Green()/255.0, colour.Blue()/255.0))
##left : the left side of the subplots of the figure
## | right : the right side of the subplots of the figure
## | bottom : the bottom of the subplots of the figure
## | top : the top of the subplots of the figure
## | wspace : the amount of width reserved for blank space between subplots
## | hspace : the amount of height reserved for white space between subplots
## |
self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
##now put everything in a sizer
sizer = wx.BoxSizer(wx.VERTICAL)
# This way of adding to sizer allows resizing
sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
self.SetSizer(sizer)
self.Fit()
##now finally create the actual plot
##self.axes = self.fig.add_subplot(111)
self.axes = self.fig.add_axes((0.16,0.08,0.90,0.85)) ##left,bottom,width,height
self.plot = self.axes.plot([0,0],[0,0], 'b', animated=True)
self.naohistoryplot = self.axes.plot([0,0],[0,0], 'r', animated=True)
self.naohistoryx = list()
self.naohistoryy = list()
self.naoplot = self.axes.plot([0,0],[0,0], 'r', marker='o', markersize=4, animated=True)
self.leftedgeplot = self.axes.plot([0,0],[0,0], 'orange', marker='o', markersize=4, linewidth=0, animated=True)
self.rightedgeplot = self.axes.plot([0,0],[0,0], 'purple', marker='o', markersize=4, linewidth=0, animated=True)
##plot formatting
self.axes.set_title('Laser Image', fontsize='10')
#self.axes.set_xlabel('y (cm)', fontsize='10')
#self.axes.set_ylabel('x (cm)', fontsize='10')
ticks = numpy.arange(-450, 450+100, 100)
labels = [str(tick) for tick in ticks]
self.axes.set_yticks(ticks)
self.axes.set_yticklabels(labels, fontsize=8)
self.axes.set_ylim(ticks[0], ticks[-1])
ticks = numpy.arange(0, 450+100, 100)
labels = [str(tick) for tick in ticks]
self.axes.set_xticks(ticks)
self.axes.set_xticklabels(labels,fontsize=8)
self.axes.set_xlim(ticks[0], ticks[-1])
self.canvas.draw()
self.canvas.gui_repaint()
# save the clean slate background -- everything but the animated line
# is drawn and saved in the pixel buffer background
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
def setNaoFinder(self, finder):
""" """
self.NAOFinder = finder
def updateData(self, data, naox, naoy):
"""updateData. Updates the data that this panel is displaying.
"""
self.x = data[0]
self.y = data[1]
self.plot[0].set_data(self.x, self.y)
self.naoplot[0].set_data([naox,naox], [naoy, naoy])
self.naohistoryx.append(naox)
self.naohistoryy.append(naoy)
if len(self.naohistoryx) > 400:
del self.naohistoryx[0]
del self.naohistoryy[0]
self.naohistoryplot[0].set_data(self.naohistoryx, self.naohistoryy)
leftx = list()
lefty = list()
for leftedge in self.NAOFinder.LeftEdges:
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import gui_repaint [as 别名]
#.........这里部分代码省略.........
)
# self.canvas.draw()
self.ybuffer = self.yvalues
except IndexError:
self.ybuffer = self.yvalues
# check if data acquisition has been stopped
if len(self.parentPanel.acquirelist) == 0:
self.currenttime = self.timeaxis[self.samples_counter - 1]
self.newstarttime = self.currenttime + datetime.timedelta(seconds=-3)
self.axes.set_xlim((date2num(self.newstarttime), date2num(self.currenttime)))
self.axes.xaxis.set_ticklabels(
self.createXTickLabels(self.currenttime),
rotation=30,
ha="right",
size="smaller",
name="Calibri",
)
self.lines[0].set_data(self.xvalues, self.yvalues)
self.canvas.draw()
self.buff_counter = 0
break
# if not, then the buff_counter exceeded the current length of the dynamic list (ecg_leadII)
pass
# plot remaining samples, then exit plot method
# para san to uli?
self.currenttime = self.timeaxis[self.samples_counter - 1]
self.newstarttime = self.currenttime + datetime.timedelta(seconds=-3)
self.axes.set_xlim((date2num(self.newstarttime), date2num(self.currenttime)))
self.axes.xaxis.set_ticklabels(
self.createXTickLabels(self.currenttime), rotation=30, ha="right", size="smaller", name="Calibri"
)
self.lines[0].set_data(self.xvalues, self.yvalues)
self.canvas.draw()
# clear up the buffer for checking
self.ybuffer = [0]
self.ysamples_counter = 0
print "Plot Thread stopped"
def createXTickLabels(self, currenttime):
""" set the x-axis in seconds.milliseconds format relative to the start time of recording """
ticklabels = []
startInSec = str(self.starttime.second)
startInmSec = str(self.starttime.microsecond / 1000)
start = float(startInSec + "." + startInmSec)
currentInSec = str(currenttime.second)
currentInmSec = str(currenttime.microsecond / 1000)
current = float(currentInSec + "." + currentInmSec)
delta = current - start
for i in range(16):
ticklabels.insert(0, "%.2f" % delta)
delta -= 0.2
return ticklabels
def createYTickLabels(self, ymin):
""" set the x-axis in voltage values of the ECG samples """
ticklabels = []
for i in range(18):
ticklabels.append(ymin)
ymin += 0.5
return ticklabels
def addSlider(self, valmax):
""" put a slider widget to navigate through the whole ECG plot """
### FIX ME: Make all time objects as parameters??? (for flexibility)
### Maybe the self.endtime? Kase constant lagi ang starting point
### added valmax as the endtime parameter
self.axtime = self.figure.add_axes([0.125, 0.1, 0.775, 0.03])
self.time_scroller = matplotlib.widgets.Slider(
self.axtime, "", date2num(self.starttime), date2num(valmax), valinit=date2num(self.starttime)
)
self.time_scroller.on_changed(self.updateWindow)
def updateWindow(self, val):
""" redraw the canvas based from the slider position """
self.updatestarttime = self.time_scroller.val
self.updatecurrenttime = date2num(num2date(self.updatestarttime) + datetime.timedelta(seconds=3))
self.axes.set_xlim((self.updatestarttime, self.updatecurrenttime))
self.axes.xaxis.set_ticklabels(
self.createXTickLabels(num2date(self.updatecurrenttime)),
rotation=30,
ha="right",
size="smaller",
name="Calibri",
)
### FIX ME: Is there a conflict here?
self.canvas.draw()
self.canvas.gui_repaint()