我在Qt中嵌入了一个matplotlib图形(使用PySide作为绑定),并使用draw函数重绘图:
self.canvas.figure.draw()
我也在平移和放大这个数字,并且一直在使用draw方法显示放大(使用set_xlim和set_ylim)和平移(drag_pan和start_pan)的新视角。有没有办法重绘图,但忽略重绘任何新绘制的点?当它平移时,我正在使用blit创建新的图,但我想确保在绘制方法期间不会重做这一点并且所有内容都尽可能高效地运行
修改/更新: 下面是我如何平移的代码片段(灵感来自navigationaltoolbar的代码):
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()