diff --git a/charon_vna/gui.py b/charon_vna/gui.py index 22f0b0f..fe16b31 100644 --- a/charon_vna/gui.py +++ b/charon_vna/gui.py @@ -49,7 +49,9 @@ class PlotWidget(QWidget): self.fig = plt.Figure(figsize=(5, 4), dpi=100, tight_layout=True) self.ax = self.fig.add_subplot(111) self.set_plot_type(type_) - self.lines = [self.ax.plot([np.nan], [np.nan], label="$S_{" + str(m) + str(n) + "}$") for m, n in self.traces] + self.lines = [ + self.ax.plot([np.nan], [np.nan], label="$S_{" + str(m) + str(n) + "}$")[0] for m, n in self.traces + ] self.ax.legend(loc="upper right") canvas = FigureCanvasQTAgg(self.fig) @@ -97,14 +99,11 @@ class PlotWidget(QWidget): def update_rect(self, data: xr.DataArray, func: Callable[[npt.ArrayLike], npt.ArrayLike]) -> None: self.ax.set_xlim(data["frequency"].min().data, data["frequency"].max().data) - # remove old lines - for line in self.ax.lines: - line.remove() for ii, (m, n) in enumerate(self.traces): - self.lines[ii] = self.ax.plot(data["frequency"], func(data.sel(m=m, n=n)))[0] + self.lines[ii].set_xdata(data["frequency"]) + self.lines[ii].set_ydata(func(data.sel(m=m, n=n))) self.fig.canvas.draw() - self.fig.canvas.flush_events() def setup_logmag(self, ylim: List[float] = [-30, 30]) -> None: self.setup_rect() @@ -139,15 +138,12 @@ class PlotWidget(QWidget): rf_plt.smith(ax=self.ax, smithR=1, chart_type="z", draw_vswr=None) def update_smith(self, data: xr.DataArray) -> None: - # remove old lines - for line in self.ax.lines: - line.remove() for ii, (m, n) in enumerate(self.traces): sel = data.sel(m=m, n=n) - self.lines[ii] = self.ax.plot(sel.real, sel.imag)[0] + self.lines[ii].set_xdata(sel.real) + self.lines[ii].set_ydata(sel.imag) self.fig.canvas.draw() - self.fig.canvas.flush_events() # Subclass QMainWindow to customize your application's main window