def plot_signal(self): if self.signal_plot is not None: self.signal_plot.plot() return # Create the figure self.xlabel = '%s' % str(self.axes_manager.signal_axes[0]) if self.axes_manager.signal_axes[0].units is not Undefined: self.xlabel += ' (%s)' % self.axes_manager.signal_axes[0].units self.ylabel = self.quantity_label self.axis = self.axes_manager.signal_axes[0] sf = signal1d.Signal1DFigure(title=self.signal_title + " Signal") sf.xlabel = self.xlabel sf.ylabel = self.ylabel sf.axis = self.axis if sf.ax is None: sf.create_axis() sf.axes_manager = self.axes_manager self.signal_plot = sf # Create a line to the left axis with the default indices sl = signal1d.Signal1DLine() is_complex = np.iscomplexobj(self.signal_data_function()) sl.autoscale = True if not is_complex else False sl.data_function = self.signal_data_function sl.plot_indices = True if self.pointer is not None: color = self.pointer.color else: color = 'red' sl.set_line_properties(color=color, type='step') # Add the line to the figure: sf.add_line(sl) # If the data is complex create a line in the left axis with the # default coordinates if is_complex: sl = signal1d.Signal1DLine() sl.autoscale = True sl.data_function = self.signal_data_function sl.plot_coordinates = True sl._plot_imag = True sl.set_line_properties(color="blue", type='step') # Add extra line to the figure sf.add_line(sl) self.signal_plot = sf sf.plot() if sf.figure is not None: if self.axes_manager.navigation_axes: self.signal_plot.figure.canvas.mpl_connect( 'key_press_event', self.axes_manager.key_navigator) if self.navigator_plot is not None: self.navigator_plot.events.closed.connect( self._on_navigator_plot_closing, []) sf.events.closed.connect(self.close_navigator_plot, []) self.signal_plot.figure.canvas.mpl_connect( 'key_press_event', self.key2switch_right_pointer) self.navigator_plot.figure.canvas.mpl_connect( 'key_press_event', self.key2switch_right_pointer) self.navigator_plot.figure.canvas.mpl_connect( 'key_press_event', self.axes_manager.key_navigator)
def add_right_pointer(self): if self.signal_plot.right_axes_manager is None: self.signal_plot.right_axes_manager = \ copy.deepcopy(self.axes_manager) if self.right_pointer is None: pointer = self.assign_pointer() self.right_pointer = pointer(self.signal_plot.right_axes_manager) # The following is necessary because e.g. a line pointer does not # have size if hasattr(self.pointer, "size"): self.right_pointer.size = self.pointer.size self.right_pointer.color = 'blue' self.right_pointer.connect_navigate() self.right_pointer.set_mpl_ax(self.navigator_plot.ax) if self.right_pointer is not None: for axis in self.axes_manager.navigation_axes[self. _pointer_nav_dim:]: self.signal_plot.right_axes_manager._axes[ axis.index_in_array] = axis rl = signal1d.Signal1DLine() rl.autoscale = True rl.data_function = self.signal_data_function rl.set_line_properties(color=self.right_pointer.color, type='step') self.signal_plot.create_right_axis() self.signal_plot.add_line(rl, ax='right') rl.plot_indices = True rl.text_position = ( 1., 1.05, ) rl.plot() self.right_pointer_on = True
def add_right_pointer(self, **kwargs): if self.signal_plot.right_axes_manager is None: self.signal_plot.right_axes_manager = \ copy.deepcopy(self.axes_manager) if self.right_pointer is None: pointer = self.assign_pointer() self.right_pointer = pointer(self.signal_plot.right_axes_manager) # The following is necessary because e.g. a line pointer does not # have size if hasattr(self.pointer, "size"): self.right_pointer.size = self.pointer.size self.right_pointer.color = 'blue' self.right_pointer.connect_navigate() self.right_pointer.set_mpl_ax(self.navigator_plot.ax) if self.right_pointer is not None: for axis in self.axes_manager.navigation_axes[self. _pointer_nav_dim:]: self.signal_plot.right_axes_manager._axes[ axis.index_in_array] = axis rl = signal1d.Signal1DLine() rl.data_function = self.signal_data_function rl.set_line_properties(color=self.right_pointer.color, type='step') self.signal_plot.create_right_axis() self.signal_plot.add_line(rl, ax='right', connect_navigation=True) rl.plot_indices = True rl.text_position = ( 1., 1.05, ) rl.plot(**kwargs) self.right_pointer_on = True # because we added the right axis, we need to redraw the canvas to # update the background self.signal_plot.figure.canvas.draw_idle()
def add_right_pointer(self, **kwargs): if self.signal_plot.right_axes_manager is None: self.signal_plot.right_axes_manager = \ copy.deepcopy(self.axes_manager) if self.right_pointer is None: pointer = self.assign_pointer() self.right_pointer = pointer(self.signal_plot.right_axes_manager) # The following is necessary because e.g. a line pointer does not # have size if hasattr(self.pointer, "size"): self.right_pointer.size = self.pointer.size self.right_pointer.color = 'blue' self.right_pointer.connect_navigate() self.right_pointer.set_mpl_ax(self.navigator_plot.ax) if self.right_pointer is not None: for axis in self.axes_manager.navigation_axes[self. _pointer_nav_dim:]: self.signal_plot.right_axes_manager._axes[ axis.index_in_array] = axis rl = signal1d.Signal1DLine() rl.data_function = self.signal_data_function rl.set_line_properties(color=self.right_pointer.color, type='step') self.signal_plot.create_right_axis() self.signal_plot.add_line(rl, ax='right', connect_navigation=True) rl.plot_indices = True rl.text_position = ( 1., 1.05, ) rl.plot(**kwargs) self.right_pointer_on = True if hasattr(self.signal_plot.figure, 'tight_layout'): try: self.signal_plot.figure.tight_layout() except BaseException: # tight_layout is a bit brittle, we do this just in case it # complains pass
def plot_navigator(self, colorbar=True, scalebar=True, scalebar_color="white", axes_ticks=None, saturated_pixels=None, vmin=None, vmax=None, no_nans=False, centre_colormap="auto", title=None, min_aspect=0.1, **kwds): if self.axes_manager.navigation_dimension == 0: return if self.navigator_data_function is None: return if self.navigator_data_function == "slider": self._get_navigation_sliders() return title = title or self.signal_title + " Navigator" if self.signal_title else "" if self.navigator_plot is not None: self.navigator_plot.plot() return elif len(self.navigator_data_function().shape) == 1: # Create the figure sf = signal1d.Signal1DFigure(title=title) axis = self.axes_manager.navigation_axes[0] sf.xlabel = '%s' % str(axis) if axis.units is not Undefined: sf.xlabel += ' (%s)' % axis.units sf.ylabel = r'$\Sigma\mathrm{data\,over\,all\,other\,axes}$' sf.axis = axis sf.axes_manager = self.axes_manager self.navigator_plot = sf # Create a line to the left axis with the default # indices sl = signal1d.Signal1DLine() sl.data_function = self.navigator_data_function sl.set_line_properties(color='blue', type='step') # Add the line to the figure sf.add_line(sl) sf.plot() self.pointer.set_mpl_ax(sf.ax) if self.axes_manager.navigation_dimension > 1: self._get_navigation_sliders() for axis in self.axes_manager.navigation_axes[:-2]: axis.events.index_changed.connect(sf.update, []) sf.events.closed.connect( partial(axis.events.index_changed.disconnect, sf.update), []) self.navigator_plot = sf elif len(self.navigator_data_function().shape) >= 2: imf = image.ImagePlot() imf.data_function = self.navigator_data_function imf.colorbar = colorbar imf.scalebar = scalebar imf.scalebar_color = scalebar_color imf.axes_ticks = axes_ticks imf.saturated_pixels = saturated_pixels imf.vmin = vmin imf.vmax = vmax imf.no_nans = no_nans imf.centre_colormap = centre_colormap imf.min_aspect = min_aspect # Navigator labels if self.axes_manager.navigation_dimension == 1: imf.yaxis = self.axes_manager.navigation_axes[0] imf.xaxis = self.axes_manager.signal_axes[0] elif self.axes_manager.navigation_dimension >= 2: imf.yaxis = self.axes_manager.navigation_axes[1] imf.xaxis = self.axes_manager.navigation_axes[0] if self.axes_manager.navigation_dimension > 2: self._get_navigation_sliders() for axis in self.axes_manager.navigation_axes[2:]: axis.events.index_changed.connect(imf.update, []) imf.events.closed.connect( partial(axis.events.index_changed.disconnect, imf.update), []) imf.title = title if "cmap" not in kwds.keys() or kwds['cmap'] is None: kwds["cmap"] = preferences.Plot.cmap_navigator imf.plot(**kwds) self.pointer.set_mpl_ax(imf.ax) self.navigator_plot = imf
def plot_navigator(self, title=None, **kwargs): """ Parameters ---------- title : str, optional Title of the navigator. The default is None. **kwargs : dict The kwargs are passed to plot method of :py:meth:`hyperspy.drawing.image.ImagePlot` or :py:meth:`hyperspy.drawing.signal1d.Signal1DLine`. """ if self.axes_manager.navigation_dimension == 0: return if self.navigator_data_function is None: return if self.navigator_data_function == "slider": self._get_navigation_sliders() return title = title or self.signal_title + " Navigator" if self.signal_title else "" if len(self.navigator_data_function().shape) == 1: # Create the figure sf = signal1d.Signal1DFigure(title=title) axis = self.axes_manager.navigation_axes[0] sf.xlabel = '%s' % str(axis) if axis.units is not Undefined: sf.xlabel += ' (%s)' % axis.units sf.ylabel = r'$\Sigma\mathrm{data\,over\,all\,other\,axes}$' sf.axis = axis sf.axes_manager = self.axes_manager self.navigator_plot = sf # Create a line to the left axis with the default indices sl = signal1d.Signal1DLine() sl.data_function = self.navigator_data_function # Set all kwargs value to the image figure before passing the rest # of the kwargs to plot method of the image figure for key in list(kwargs.keys()): if hasattr(sl, key): setattr(sl, key, kwargs.pop(key)) sl.set_line_properties(color='blue', type='step') # Add the line to the figure sf.add_line(sl) sf.plot() self.pointer.set_mpl_ax(sf.ax) if self.axes_manager.navigation_dimension > 1: self._get_navigation_sliders() for axis in self.axes_manager.navigation_axes[:-2]: axis.events.index_changed.connect(sf.update, []) sf.events.closed.connect( partial(axis.events.index_changed.disconnect, sf.update), []) self.navigator_plot = sf elif len(self.navigator_data_function().shape) >= 2: # Create the figure imf = image.ImagePlot(title=title) imf.data_function = self.navigator_data_function # Set all kwargs value to the image figure before passing the rest # of the kwargs to plot method of the image figure for key, value in list(kwargs.items()): if hasattr(imf, key): setattr(imf, key, kwargs.pop(key)) # Navigator labels if self.axes_manager.navigation_dimension == 1: imf.yaxis = self.axes_manager.navigation_axes[0] imf.xaxis = self.axes_manager.signal_axes[0] elif self.axes_manager.navigation_dimension >= 2: imf.yaxis = self.axes_manager.navigation_axes[1] imf.xaxis = self.axes_manager.navigation_axes[0] if self.axes_manager.navigation_dimension > 2: self._get_navigation_sliders() for axis in self.axes_manager.navigation_axes[2:]: axis.events.index_changed.connect(imf.update, []) imf.events.closed.connect( partial(axis.events.index_changed.disconnect, imf.update), []) if "cmap" not in kwargs.keys() or kwargs['cmap'] is None: kwargs["cmap"] = preferences.Plot.cmap_navigator imf.plot(**kwargs) self.pointer.set_mpl_ax(imf.ax) self.navigator_plot = imf if self.navigator_plot is not None: self.navigator_plot.events.closed.connect( self._on_navigator_plot_closing, [])
def plot_navigator(self): if self.axes_manager.navigation_dimension == 0: return if self.navigator_data_function is None: return if self.navigator_data_function is "slider": navigation_sliders(self.axes_manager.navigation_axes, title=self.signal_title + " navigation sliders") return if self.navigator_plot is not None: self.navigator_plot.plot() return elif len(self.navigator_data_function().shape) == 1: # Create the figure sf = signal1d.Signal1DFigure( title=self.signal_title + ' Navigator' if self.signal_title else "") axis = self.axes_manager.navigation_axes[0] sf.xlabel = '%s' % str(axis) if axis.units is not Undefined: sf.xlabel += ' (%s)' % axis.units sf.ylabel = r'$\Sigma\mathrm{data\,over\,all\,other\,axes}$' sf.axis = axis sf.axes_manager = self.axes_manager self.navigator_plot = sf # Create a line to the left axis with the default # indices sl = signal1d.Signal1DLine() sl.data_function = self.navigator_data_function sl.set_line_properties(color='blue', type='step') # Add the line to the figure sf.add_line(sl) sf.plot() self.pointer.set_mpl_ax(sf.ax) if self.axes_manager.navigation_dimension > 1: navigation_sliders(self.axes_manager.navigation_axes, title=self.signal_title + " navigation sliders") for axis in self.axes_manager.navigation_axes[:-2]: axis.events.index_changed.connect(sf.update, []) sf.events.closed.connect( partial(axis.events.index_changed.disconnect, sf.update), []) self.navigator_plot = sf elif len(self.navigator_data_function().shape) >= 2: imf = image.ImagePlot() imf.data_function = self.navigator_data_function # Navigator labels if self.axes_manager.navigation_dimension == 1: imf.yaxis = self.axes_manager.navigation_axes[0] imf.xaxis = self.axes_manager.signal_axes[0] elif self.axes_manager.navigation_dimension >= 2: imf.yaxis = self.axes_manager.navigation_axes[1] imf.xaxis = self.axes_manager.navigation_axes[0] if self.axes_manager.navigation_dimension > 2: navigation_sliders(self.axes_manager.navigation_axes, title=self.signal_title + " navigation sliders") for axis in self.axes_manager.navigation_axes[2:]: axis.events.index_changed.connect(imf.update, []) imf.events.closed.connect( partial(axis.events.index_changed.disconnect, imf.update), []) imf.title = self.signal_title + ' Navigator' imf.plot() self.pointer.set_mpl_ax(imf.ax) self.navigator_plot = imf