当前位置: 首页>>代码示例>>Python>>正文


Python Figure.draw_artist方法代码示例

本文整理汇总了Python中matplotlib.figure.Figure.draw_artist方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.draw_artist方法的具体用法?Python Figure.draw_artist怎么用?Python Figure.draw_artist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.figure.Figure的用法示例。


在下文中一共展示了Figure.draw_artist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: VelocityPanel

# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import draw_artist [as 别名]

#.........这里部分代码省略.........
        self.y_axes = self.fig.add_subplot(132)                 ## the y velocity
        self.m_axes = self.fig.add_subplot(133)                 ## the magnitude of the velocity
        #self.axes = self.fig.add_axes((0.1,0.1,0.85,0.8))        ##left,bottom,width,height
        
        self.x_plot = self.x_axes.plot([0,1],[0,1],'b', animated=True)
        self.y_plot = self.y_axes.plot([0,1],[0,1],'b', animated=True)
        self.m_plot = self.m_axes.plot([0,1],[0,1],'r', animated=True)
        
        self.x_axes.set_title('X', fontsize='10')
        self.y_axes.set_title('Y', fontsize='10')
        self.m_axes.set_title('M', fontsize='10')
        self.x_axes.set_ylabel('Velocity (cm/s)', fontsize='10')
        #self.axes.set_ylabel('x (cm)', fontsize='10')

        ##plot formatting
        self._formatAxes(self.x_axes)
        self._formatAxes(self.y_axes)
        self._formatAxes(self.m_axes)
        #self.axes.set_title('Velocity', fontsize='10')
        
        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.fig.bbox)
        
    def _initFigure(self):
        ##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))    

        self.canvas = FigureCanvasWxAgg(self, -1, self.fig)

        self.fig.subplots_adjust(left=0.05,right=0.95,wspace=0.08)

        ##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()
        
    def _formatAxes(self, axes):
        """ """
        ticks = numpy.arange(-25, 25+5, 5)
        labels = [str(tick) for tick in ticks]              # velocity
        axes.set_yticks(ticks)
        axes.set_yticklabels(labels, fontsize=8)
        ticks = numpy.arange(0, 10+1.0, 1.0)                # time
        labels = [str(tick) for tick in ticks]              
        axes.set_xticks(ticks)
        axes.set_xticklabels(labels,fontsize=8)
        
        #if axes == self.m_axes:
        #    self.axes.set_xlabel('time (s)', fontsize='10')
        #self.axes.set_ylabel(' (mm)', fontsize='10')
        
        
    
    def updateData(self, velx, vely, vel):
        """updateData. Updates the data that this panel is displaying.
        """
        self.VelocitiesX.append(velx)
        self.VelocitiesY.append(vely)
        self.Velocities.append(vel)
        timenow = time.time()
        self.Times.append(timenow)
        if timenow - self.Times[0] > 10:
            del self.Times[0]
            del self.VelocitiesX[0]
            del self.VelocitiesY[0]
            del self.Velocities[0]
        
        self.x_plot[0].set_data(numpy.array(self.Times) - self.Times[0], self.VelocitiesX)
        self.y_plot[0].set_data(numpy.array(self.Times) - self.Times[0], self.VelocitiesY)
        self.m_plot[0].set_data(numpy.array(self.Times) - self.Times[0], self.Velocities)
        
        # restore the clean slate background
        self.canvas.restore_region(self.background)
        # just draw the animated artist
        self.fig.draw_artist(self.x_plot[0])
        self.fig.draw_artist(self.y_plot[0])
        self.fig.draw_artist(self.m_plot[0])
        # just redraw the axes rectangle
        self.canvas.blit(self.fig.bbox)

    def OnPolarPanelPaint(self, event):
        pass
开发者ID:RJianCheng,项目名称:naowalkoptimiser,代码行数:104,代码来源:VelocityPanel.py

示例2: Frame

# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import draw_artist [as 别名]
class Frame(wx.Frame):
	def __init__(self):
		wx.Frame.__init__(self, None, -1)

		self.SetTitle('Blitting Example')

		# Figure layout.
		self.fig = Figure((5,4), 100)
		self.canvas = FigureCanvas(self, -1, self.fig)

		# BEGIN: Widget layout.
		self.wx_widgets = []
		sizer = wx.BoxSizer()
		sizer.Add(self.canvas, proportion=1, flag=wx.EXPAND)
		self.SetSizer(sizer)
		self.Fit()
		# END: Widget layout.

		# BEGIN: Plot initialization.
		self.axes = self.fig.add_subplot(111) 
		self.line1_ydata = [numpy.random.normal()]
		self.line2_ydata = [numpy.random.normal()]
		self.line1, = self.axes.plot(self.line1_ydata, color='b', animated=BLIT)
		self.line2, = self.axes.plot(self.line2_ydata, color='r', animated=BLIT)
		self.fps_label = self.axes.annotate("FPS: 0", (0.01, 0.95), xycoords="axes fraction", animated=BLIT)
		self.xaxis = self.axes.get_xaxis()
		self.yaxis = self.axes.get_yaxis()
		# END: Plot initialization.

		# BEGIN: Timers
		# IMPORTANT: Use wx.EVT_TIMER for redraw to avoid resource conflicts/crashes.
		self.redraw_timer = wx.Timer(self, wx.NewId())   # Plot refresh timer.
		self.redraw_timer.Start(50)
		wx.EVT_TIMER(self, self.redraw_timer.GetId(), self.redraw) 
		self.frames = 0
		self.start = time.time()
		# END: Timers

	###############################
	# BEGIN: Plot related methods #
	###############################
	def redraw(self, evt):
	
		# update the ydata, normally this would be done by SyncDB
		y1 = self.line1_ydata[-1] + numpy.random.normal()
		y2 = self.line2_ydata[-1] + numpy.random.normal()
		self.line1_ydata.append(y1)
		self.line2_ydata.append(y2)
		
		self.line1.set_data(range(len(self.line1_ydata)), self.line1_ydata)
		self.line2.set_data(range(len(self.line2_ydata)), self.line2_ydata)
		self.axes.set_ylim(min(self.line1_ydata + self.line2_ydata), max(self.line1_ydata + self.line2_ydata))
		self.axes.set_xlim(max(0, len(self.line1_ydata)-100), max(100, len(self.line1_ydata)))
		self.fps_label.set_text("FPS: %.2f" % (self.frames / float(time.time() - self.start)))
		
		if BLIT:
			self.fig.draw_artist(self.fig)
			self.axes.draw_artist(self.line1)
			self.axes.draw_artist(self.line2)
			self.axes.draw_artist(self.fps_label)
			self.fig.draw_artist(self.xaxis)
			self.fig.draw_artist(self.yaxis)
			self.canvas.blit(self.fig.bbox)
		else:
			self.canvas.draw()
		
		self.frames += 1
开发者ID:thetomcraig,项目名称:redwood,代码行数:69,代码来源:blitting.py


注:本文中的matplotlib.figure.Figure.draw_artist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。