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


Python FigureCanvasGTKAgg.restore_region方法代码示例

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


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

示例1: Plot

# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import restore_region [as 别名]

#.........这里部分代码省略.........
                         if inner is not None])
        delta = y_max - y_min
        if delta < 1E-10:
            return modified

        br = 0.2
        if y_min < self.settings['y_bounds'][0]:
            self.settings['y_bounds'] =\
                (y_min-br*delta, self.settings['y_bounds'][1])
            modified = True
        elif y_min > self.settings['y_bounds'][0] + br*delta:
            self.settings['y_bounds'] =\
                (y_min, self.settings['y_bounds'][1])
            modified = True

        if y_max > self.settings['y_bounds'][1]:
            self.settings['y_bounds'] =\
                (self.settings['y_bounds'][0], y_max+br*delta)
            modified = True
        elif y_max < self.settings['y_bounds'][1] - br*delta:
            self.settings['y_bounds'] =\
                (self.settings['y_bounds'][0], y_max)
            modified = True

        return modified

    def update_legends(self):
        if self.settings['legends'] is not None:
            for n in range(self.n_lines):
                point = self.y[n][-1]
                self.legends.set_legend_text(n, point)

    def _quick_update(self):
        if self.first_update:
            self._full_update()
            self.first_update = False
        self.canvas.restore_region(self.background)
        [line.set_ydata(y_data) for line, y_data in zip(self.lines, self.y)]
        [self.ax.draw_artist(line) for line in self.lines]
        # just redraw the axes rectangle
        self.canvas.blit(self.ax.bbox)

    def _full_update(self, widget=None, size=None):
        # This does not work properly, FIXME
        if widget is not None:
            if [size.width, size.height] != self.saved_window_size:
                self.saved_window_size = [size.width, size.height]
            else:
                return
        # Plot
        if self.first_update:
            plot = self.ax.semilogy if self.settings['logscale'] else self.ax.plot
            self.lines = [plot(x, y, style, color=color, animated=True)[0]
                          for x, y, color, style in
                          zip(self.x, self.y, self.line_colors, self.line_styles)]
            # Title and axis labels
            if self.settings['title'] is not None:
                self.ax.set_title(self.settings['title'])
            if self.settings['x_label'] is not None:
                self.ax.set_xlabel(self.settings['x_label'])
            if self.settings['y_label'] is not None:
                self.ax.set_ylabel(self.settings['y_label'])
            self.fig.subplots_adjust(left=0.25, bottom=0.15)
        else:
            [line.set_ydata(y_data) for line, y_data in zip(self.lines, self.y)]

        # Get or set boundaries
        if self.first_update:
            if self.settings['x_bounds'] is None:
                self.settings['x_bounds'] = self.ax.get_xlim()
            if self.settings['y_bounds'] is None:
                self.settings['y_bounds'] = self.ax.get_ylim()
        else:
            self.ax.set_xlim(*self.settings['x_bounds'])
            self.ax.set_ylim(*self.settings['y_bounds'])

        # Get the background for later use
        self.canvas.draw()
        self.background = self.canvas.copy_from_bbox(self.ax.bbox)
        # First draw update
        [line.set_animated(False) for line in self.lines]
        self.canvas.draw()
        [line.set_animated(True) for line in self.lines]

    def _get_colors(self, n):
        """ Generate colors for the lines if they are not provided. First use
        6 of the standard colors and then generate random colors

        Parameters:
            n -- the number of colors requested
        """
        standard = ['r', 'g', 'b', 'c', 'm', 'k']
        if n <= len(standard):
            out = standard[:n]
        else:
            out = standard
        if n > len(standard):
            for i in range(len(standard), n):
                out.append((random.random(), random.random(), random.random()))
        return out
开发者ID:BBelonder,项目名称:PyExpLabSys,代码行数:104,代码来源:LivePlotsCommon.py

示例2: SensorWindow

# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import restore_region [as 别名]

#.........这里部分代码省略.........
	def close_from_mainthread(self):
		print "close from mainthread"
		self.builder.get_object("window1").destroy()


	def toggle_lamp(self):
		print "toggle lamp!!"
		self.img = self.builder.get_object("image1")
		if(self.lamp):
			self.lamp = False
			self.img.set_from_file("off.svg")
		else:
			self.lamp = True
			self.img.set_from_file("on.svg")

	def update_line(self, *args):

		if self._stopped:
			self.destroy_callback(None)
			return False

		if self.background1 is None:
			return True

		cur_time = time.time()
		pixel_offset = int((cur_time - self.start) * 40.)
		dx_pixel = pixel_offset - self.prev_pixel_offset
		self.prev_pixel_offset = pixel_offset
		dx_data = self.get_dx_data(dx_pixel) #cur_time - self.prev_time)

		x0 = self.x0
		self.x0 += dx_data
		self.prev_time = cur_time

		self.ax.set_xlim(self.x0-2, self.x0+0.1)

		# restore background which will plot lines from previous plots
		self.restore_background_shifted(dx_pixel) #x0, self.x0)

		# now plot line segment within [x0, x0+dx_data],
		# Note that we're only plotting a line between [x0, x0+dx_data].
		xx = np.array([x0, self.x0])
		for i in range(len(self.lines)):
			line = self.lines[i]
			line.set_xdata(xx)

			# the for loop below could be improved by using collection.
			line.set_ydata(np.array([self.value[i], self.value[i]]))
			self.ax.draw_artist(line)

		self.background2 = self.canvas.copy_from_bbox(self.get_bg_bbox())

		self.ax.draw_artist(self.ax.xaxis)
		self.ax.draw_artist(self.ax.yaxis)

		self.canvas.blit(self.ax.get_figure().bbox)
		return True

	def get_dx_data(self, dx_pixel):
		tp = self.ax.transData.inverted().transform_point
		x0, y0 = tp((0, 0))
		x1, y1 = tp((dx_pixel, 0))
		return (x1 - x0)

	def get_bg_bbox(self):
		return self.ax.bbox.padded(-3)

	def save_bg(self):
		self.background1 = self.canvas.copy_from_bbox(self.ax.get_figure().bbox)
		self.background2 = self.canvas.copy_from_bbox(self.get_bg_bbox())

	def on_draw(self, *args):
		self.save_bg()
		return False

	def restore_background_shifted(self, dx_pixel):
		"""
		restore bacground shifted by dx in data coordinate. This only
		works if the data coordinate system is linear.
		"""

		# restore the clean slate background
		self.canvas.restore_region(self.background1)

		# restore subregion (x1+dx, y1, x2, y2) of the second bg
		# in a offset position (x1-dx, y1)
		x1, y1, x2, y2 = self.background2.get_extents()
		self.canvas.restore_region(self.background2,
					bbox=(x1+dx_pixel, y1, x2, y2),
					xy=(x1-dx_pixel, y1))

		return dx_pixel

	def update(self, data):
		if type(data) == ListType:
			assert(len(self.lines) == len(data))
			self.value = data
		else:
			assert(len(self.lines) == 1)
			self.value = [data]
开发者ID:BrzTit,项目名称:gr-ieee802-15-4,代码行数:104,代码来源:sensor_window.py

示例3: plot_data

# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import restore_region [as 别名]
class plot_data(object):
    '''
    Creates a object with a widget ready to be inserted in a GTK window, in wich we can 
    plot the current robot variables.
                    
    calling the object will update the plot with the data passed
    calling the method set_values you can change the color, units a/o length
    '''
    def __init__(self, units=None, colors=None, length=None):
        '''
         Modifiable attributes:
         colors: color of the lines - list of strings: len = 4 default: ['r', 'g', 'b', 'y']
         units: units of the plots - list of strings: len = 2 default: [rad, N*m]
         length: maximum period of time to show - int or float default: 100
        
         Accessible attributes:
         main_widget: widget to be inserted in a GTK window
        '''
        self.set_values(units, colors, length)
        # Define axis and lines labels
        self.__xlabel = 'Time - s'
        self.__ylabel = ['Angular position - '+self.__units[0], 'Angular velocity - '+self.__units[0]+'/s', 
                         'Angular acceleration - '+self.__units[0]+'/s**2', 'Torque - '+self.__units[1]]
        self.__lines_labels = ["Shoulder_X", "Shoulder_Y", "Shoulder_Z", "Elbow_Z"]
        # Define font size for the legend
        self.__font = font_manager.FontProperties(size = 8)
        # Create the Figure and the plot
        self.__figure = figure()
        self.__sub_figures = []
        self.__backgrounds = []
        self.__lines = [[], [], [], []]
        # Create the widget, a FigureCanvas containing our Figure
        self.main_widget = FigureCanvas(self.__figure)
        # Create and configure the subplots
        for index in xrange(4):
            self.__sub_figures.append(self.__figure.add_subplot(221+index))
            self.__sub_figures[index].grid(True)
            self.__sub_figures[index].set_xlabel(self.__xlabel, fontsize = 9)
            self.__sub_figures[index].set_ylabel(self.__ylabel[index], fontsize = 9)
            #FIXME: change the y limits, the currents are for test only
            self.__sub_figures[index].set_ylim(-256, 256)
            self.__sub_figures[index].set_xlim(0, self.__lenght)
            self.__sub_figures[index].tick_params(axis='both', which = 'major', labelsize = 10)
            self.__sub_figures[index].tick_params(axis='both', which = 'minor', labelsize = 8)
            for l_index in xrange(4):
                self.__lines[index].append(self.__sub_figures[index].plot([], [], self.__colors[l_index], animated = True)[0])
            #Saving the firsts background to redraw 
            self.__backgrounds.append(self.main_widget.copy_from_bbox(self.__sub_figures[index].bbox))
        #Setting up the legend box
        figlegend(self.__lines[0], self.__lines_labels, loc = "upper center", prop= self.__font)
        #Show and set initial data
        self.main_widget.draw()
        self.__reset_data()
        return
        
    def __call__(self, values, d_time):
        '''
        values: object with the current values to plot, in the form of attributes like:
            self.position = []
            self.velocity = []
            self.acceleration = []
            self.torque = []
        
        d_time: current time, since the plot starts - int or float
        '''
        self.__time.append(d_time)
        if (d_time >= (self.__time[0] + self.__lenght)):
            self.__reset_data()
            self.__time.append(d_time)
            for index in xrange(4):
                self.__sub_figures[index].set_xlim(d_time, d_time+self.__lenght)
            self.main_widget.draw()
            for index in xrange(4):
                self.__backgrounds[index] = self.main_widget.copy_from_bbox(self.__sub_figures[index].bbox)
        for index in xrange(4):
            self.main_widget.restore_region(self.__backgrounds[index])
            self.__position[index].append(values.position[index])
            self.__velocity[index].append(values.velocity[index])
            self.__acceleration[index].append(values.acceleration[index])
            self.__torque[index].append(values.torque[index])
        for index in xrange(4):
            for l_index in xrange(4):
                if index == 0:
                    self.__lines[index][l_index].set_data(self.__time, self.__position[l_index])
                elif index == 1:
                    self.__lines[index][l_index].set_data(self.__time, self.__velocity[l_index])
                elif index == 2:
                    self.__lines[index][l_index].set_data(self.__time, self.__acceleration[l_index])
                elif index == 3:
                    self.__lines[index][l_index].set_data(self.__time, self.__torque[l_index])
                self.__sub_figures[index].draw_artist(self.__lines[index][l_index])
            self.main_widget.blit(self.__sub_figures[index].bbox)
        return
        
    def __reset_data(self):
        #Create the vectors for the variables
        try: 
            type(self.__time)
        except:
            self.__time = []
#.........这里部分代码省略.........
开发者ID:xDMxosiris,项目名称:hekate,代码行数:103,代码来源:gui_widgets.py


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