1

我在 Qt 中嵌入了一个 matplotlib 图形(使用 PySide 作为绑定),并且正在使用 draw 函数重绘图形:

self.canvas.figure.draw()

我也在平移和放大这个图,并且一直使用 draw 方法从放大(使​​用 set_xlim 和 set_ylim)和平移(drag_pan 和 start_pan)显示新的视角。有没有办法重绘图形,但忽略重绘任何新绘制的点?当它平移时,我正在使用 blit 制作新图,但我想确保在 draw 方法期间不会重做,并且一切都尽可能高效地运行

编辑/更新: 下面是我如何平移的代码片段(灵感来自导航工具栏的代码):

    def on_drag(self, event):
    x, y = event.x, event.y  

    if event.button == 1 and not event.dblclick and self.zoom.zoom_level != 0:

        self._button_pressed = 1
        self.cursor.dragging_enabled = True 

        self._xypress = [] 
        for i, a in enumerate(self.canvas.figure.get_axes()):

            if (x is not None and y is not None): # and a.in_axes(event)): 
                a.start_pan(x, y, event.button)
                self._xypress.append((a))
                self._idDrag = self.canvas.mpl_connect('motion_notify_event',
                                                   self.drag_pan)  

def drag_pan(self,event):

    self.canvas.update()
    self.canvas.flush_events()  

    x, y = self.calculate_center_coords()
    self.pan_center_x = x  
    self.pan_center_y = y  

    for a in self._xypress:

        a.drag_pan(self._button_pressed, event.key, event.x, event.y)
        x_diff = self.pan_center_x / event.xdata
        y_diff = self.pan_center_y / event.ydata

        if self.zoom.zoom_level == 1:
            if ((x_diff > 1.04590 and x_diff < 1.05090) or 
                              (x_diff < 0.95715 and x_diff > 0.95215) or 
                              (y_diff > 1.03550 and y_diff < 1.04450) or
                              (y_diff < 0.97215 and y_diff > 0.96115)): 

                x, y = self.calculate_center_coords()
                self.pan_center_x = x  
                self.pan_center_y = y  

                #Method that replots points using blit
                self.panning()

    #Redraws canvas, but is probably a bottleneck
    self.canvas.draw()
4

0 回答 0