Skip to content

Commit

Permalink
Don't keep an extra reference to the canvas object around. flush even…
Browse files Browse the repository at this point in the history
…ts when updating plots.
  • Loading branch information
jzuhone committed Sep 7, 2022
1 parent 1e445d8 commit 94e320c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions xija/gui_fit/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,10 @@ def __init__(self, plot_name, plots_box):
self.ax = self.fig.add_subplot(111, sharex=plots_box.default_ax)
self.ax.autoscale(enable=False, axis='x')

self.canvas = canvas
self.plots_box = plots_box
self.main_window = self.plots_box.main_window
self.selecter = self.canvas.mpl_connect("button_press_event", self.select)
self.releaser = self.canvas.mpl_connect("button_release_event", self.release)
self.selecter = self.fig.canvas.mpl_connect("button_press_event", self.select)
self.releaser = self.fig.canvas.mpl_connect("button_release_event", self.release)

self.ly = None
self.limits = None
Expand All @@ -556,7 +555,7 @@ def select(self, event):
grab = event.inaxes and self.main_window.show_line and \
not self.ax.get_navigate_mode()
if grab:
self.mover = self.canvas.mpl_connect('motion_notify_event', self.on_mouse_move)
self.mover = self.fig.canvas.mpl_connect('motion_notify_event', self.on_mouse_move)
self.plots_box.xline = event.xdata
self.plots_box.update_xline()
else:
Expand All @@ -571,12 +570,12 @@ def on_mouse_move(self, event):

def release(self, event):
if hasattr(self, "mover"):
self.canvas.mpl_disconnect(self.mover)
self.fig.canvas.mpl_disconnect(self.mover)

def update_xline(self):
if self.plot_name.endswith("time") and self.ly is not None:
self.ly.set_xdata(self.plots_box.xline)
self.canvas.draw_idle()
self.fig.canvas.draw_idle()

_rz_times = None

Expand Down Expand Up @@ -657,8 +656,8 @@ def update(self, first=False):
self.add_annotation("line")
if mw.show_limits:
self.add_annotation("limits")
self.canvas.draw_idle()

self.fig.canvas.draw_idle()
self.fig.canvas.flush_events()

class PlotsBox(QtWidgets.QVBoxLayout):
def __init__(self, model, main_window):
Expand Down

0 comments on commit 94e320c

Please sign in to comment.