def show(self, with_controls: bool = True, verbose: bool = False): # graph things... self._main_fig, self._x_axis = plt.subplots() self._x_axis.set_xlabel('seconds') plt.title('Shot at [%s] %.01fg, %.02f%% TDS' % (self.shot.shot_time, self.shot.bw, self.shot.tds)) time_series = self.shot.elapsed self._flow_plt, = plt.plot(time_series, self.shot.flow, label='flow (ml/s)', color='blue', lw=3.5) plt.plot(time_series, self.shot.pressure, label='pressure (bar)', color='green') # derived things if hasattr( self, '_erroneous_weight' ): # only shown when weight curve is derived from raw scale values plt.plot(time_series, self._erroneous_weight, label='error weight (g/s)', color='brown', alpha=0.6, linestyle='dashed') # tds_ratio = [(tw / w * 100) for tw, w in zip(self._tds_effect, self._smoothing(self.shot.weight, 21))] # plt.plot(time_series, tds_ratio, label='TDS ratio (%)') plt.plot(time_series, self._gravimetric_water, label='measured water (g/s)', color='brown', lw=2) self._error_line, = plt.plot(time_series, [0.0] * len(time_series), label='error (x10)', color='grey') error_data = self._error_series(self.shot.flow, self._stable_weight_t, 10) self._error_line.set_ydata( error_data) # little hack to clip large error values self._sugg_line = plt.axhline(self._corr_suggestion * 10, label='suggestion (x10)', color='pink', linestyle='dashed') self._corr_line = plt.axhline(10.0, label='correction (x10)', color='magenta', linestyle='dotted') if verbose: plt.plot(time_series, self.shot.weight, label='weight (g/s)', color='orange', linestyle='dashed') resistance, = plt.plot(time_series, [0.0] * len(time_series), label='resistance', color='yellow') resistance.set_ydata(self._resistance) plt.plot(time_series, [v * 10 for v in self._diffs], label='difference (x10)', color='red') plt.plot(time_series, [v * 10 for v in self._tds_effect], label='TDS weight (g/s, x10)', color='navy', linestyle='dashed') self._window_fill = self._x_axis.axvspan(*self._initial_window, ymin=0.0, ymax=1.0, alpha=0.15, color='green') if with_controls: # sliders plt.subplots_adjust(right=0.85, bottom=0.18) # correction slider correction_ax = plt.axes([0.87, 0.18, 0.03, 0.65]) correction_slider = Slider(correction_ax, 'correction\nvalue', orientation='vertical', valinit=1.0, valmin=0.3, valmax=2.5, valstep=0.01) if eq_within(self.shot.current_calibration, 1.0): corr_value_fmt = FuncFormatter(lambda v, p: 'x%.02f' % v) else: corr_value_fmt = FuncFormatter( lambda v, p: 'x%.03f\n(%.02f)' % (self.shot.current_calibration * v, v)) correction_slider._fmt = corr_value_fmt correction_slider.on_changed( partial(Analysis._update_flow, self, self.shot.flow)) # +- buttons plus_button_x = plt.axes([0.92, 0.27, 0.035, 0.06]) minus_button_x = plt.axes([0.92, 0.2, 0.035, 0.06]) plus_button = Button(plus_button_x, '▲') minus_button = Button(minus_button_x, '▼') plus_button.on_clicked(lambda _: correction_slider.set_val( correction_slider.val + 0.01)) minus_button.on_clicked(lambda _: correction_slider.set_val( correction_slider.val - 0.01)) # window slider window_ax = plt.axes([0.16, 0.05, 0.66, 0.03]) window_slider = RangeSlider(window_ax, 'opt.\nwindow', valmin=0.0, valmax=time_series[-1], valstep=0.1) window_slider.set_val(self._initial_window) window_slider.valtext.set_visible(False) window_slider.on_changed(partial(Analysis._update_window, self)) self._x_axis.legend() plt.show()