更改绘图时如何始终更新矩形选择器?

how update rectangleselector all time when change plot?

我在打开文件并绘制它时遇到问题我用我的矩形选择器绘制了我的图形但是当我更改并选择其他文件绘制新图形时我有 2 个矩形选择器我不知道如何更新矩形选择器当我在同一个情节中更改图形时的所有时间:

self.RS = RectangleSelector(self.axes,self.line_select_callback,
                                       drawtype='box', useblit=False,
                                       button=[1, 3],minspanx=5, minspany=5,
                                       spancoords='pixels',
                                       interactive=True, rectprops = dict(facecolor='None',edgecolor='red',alpha=5,fill=False))

        self.RS.to_draw.set_visible(True)
        self.RS.extents = (0,10,0,10)

    def line_select_callback(self, eclick, erelease):
        'eclick and erelease are the press and release events'
        x1, y1 = eclick.xdata, eclick.ydata
        x2, y2 = erelease.xdata, erelease.ydata
        self.zoom_axes=[x1,x2,y1,y2]

谢谢

在声明 self.RS 之前使用以下内容:

    try:
        self.RS.set_visible(False)
    except:
        pass