def test_plot_add_line_events(): s = hs.signals.Signal1D(np.arange(100)) s.plot() assert len(s.axes_manager.events.indices_changed.connected) == 1 figure = s._plot.signal_plot def line_function(axes_manager=None): return 100 - np.arange(100) line = Signal1DLine() line.data_function = line_function line.set_line_properties(color='blue', type='line', scaley=False) figure.add_line(line, connect_navigation=True) line.plot() assert len(line.events.closed.connected) == 1 assert len(s.axes_manager.events.indices_changed.connected) == 2 line.close() figure.close_right_axis() assert len(line.events.closed.connected) == 0 assert len(s.axes_manager.events.indices_changed.connected) == 1 figure.close() assert len(s.axes_manager.events.indices_changed.connected) == 0
def add_line(self, signal, color='b', type='step', fill_with=np.nan): axis_plt = self.signal.axes_manager.signal_axes[0] axis_sig = signal.axes_manager.signal_axes[0] rdata = fill_with * np.ones_like(axis_plt.axis) idx = axis_plt.value2index(axis_sig.low_value) fdx = axis_plt.value2index(axis_sig.high_value) + 1 def _data_f(axes_manager): rdata[idx:fdx] = signal.__call__(signal.axes_manager) return rdata def _data_f_multi(axes_manager): signal.axes_manager.trait_set(indices=axes_manager.indices) return _data_f(axes_manager=axes_manager) signal_line = Signal1DLine() if signal.axes_manager.navigation_shape == (): signal_line.data_function = _data_f else: signal_line.data_function = _data_f_multi signal_line.set_line_properties(color = color, type = type, scaley = False) self.signal._plot.signal_plot.add_line(signal_line) signal_line.autoscale = False self.signal_lines += [signal_line] signal_line.plot()
def test_plot_add_line_events(ax): s = hs.signals.Signal1D(np.arange(100)) s.plot() assert len(s.axes_manager.events.indices_changed.connected) == 1 plot = s._plot.signal_plot assert len(s._plot.signal_plot.figure.get_axes()) == 1 def line_function(axes_manager=None): return 100 - np.arange(100) line = Signal1DLine() line.data_function = line_function line.set_line_properties(color='blue', type='line', scaley=False) if ax == 'right': plot.create_right_axis() plot.right_axes_manager = copy.deepcopy(s.axes_manager) expected_axis_number = 2 expected_indices_changed_connected = 1 else: expected_axis_number = 1 expected_indices_changed_connected = 2 plot.add_line(line, ax=ax, connect_navigation=True) assert len(s._plot.signal_plot.figure.get_axes()) == expected_axis_number line.plot() assert len(line.events.closed.connected) == 1 # expected_indices_changed_connected is 2 only when adding line on the left # because for the right ax, we have a deepcopy of the axes_manager assert len(s.axes_manager.events.indices_changed.connected) == \ expected_indices_changed_connected line.close() plot.close_right_axis() assert len(s._plot.signal_plot.figure.get_axes()) == 1 assert len(line.events.closed.connected) == 0 assert len(s.axes_manager.events.indices_changed.connected) == 1 plot.close() assert len(s.axes_manager.events.indices_changed.connected) == 0 assert s._plot.signal_plot is None