def plot_navigator(self): if self.axes_manager.navigation_dimension == 0: return if self.navigator_data_function is None: 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 = spectrum.SpectrumFigure( 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.axis sf.axes_manager = self.axes_manager self.navigator_plot = sf # Create a line to the left axis with the default # indices sl = spectrum.SpectrumLine() 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.add_axes(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.connect(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.connect(imf.update) imf.title = self.signal_title + ' Navigator' imf.plot() self.pointer.add_axes(imf.ax) self.navigator_plot = imf
def plot_signal(self, **kwargs): """ Parameters ---------- **kwargs : dict The kwargs are passed to plot method of the image figure. """ super().plot_signal() imf = image.ImagePlot() imf.axes_manager = self.axes_manager imf.data_function = self.signal_data_function imf.title = self.signal_title + " Signal" imf.xaxis, imf.yaxis = self.axes_manager.signal_axes # 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)) imf.quantity_label = self.quantity_label kwargs['data_function_kwargs'] = self.signal_data_function_kwargs if "cmap" not in kwargs.keys() or kwargs['cmap'] is None: kwargs["cmap"] = preferences.Plot.cmap_signal imf.plot(**kwargs) self.signal_plot = imf if imf.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.figure.canvas.mpl_connect( 'key_press_event', self.axes_manager.key_navigator) imf.events.closed.connect(self.close_navigator_plot, []) imf.events.closed.connect(self._on_signal_plot_closing, [])
def plot_signal(self): if self.signal_plot is not None: self.signal_plot.plot() return imf = image.ImagePlot() imf.axes_manager = self.axes_manager imf.data_function = self.signal_data_function imf.title = self.signal_title + " Signal" imf.xaxis, imf.yaxis = self.axes_manager.signal_axes imf.plot_colorbar = True imf.plot() self.signal_plot = imf if self.navigator_plot is not None and imf.figure is not None: utils.on_figure_window_close(self.navigator_plot.figure, self.close_navigator_plot) utils.on_figure_window_close(imf.figure, self.close_navigator_plot) self._key_nav_cid = \ self.signal_plot.figure.canvas.mpl_connect( 'key_press_event', self.axes_manager.key_navigator) self._key_nav_cid = \ self.navigator_plot.figure.canvas.mpl_connect( 'key_press_event', self.axes_manager.key_navigator)
def plot_signal(self, colorbar=True, scalebar=True, scalebar_color="white", axes_ticks=None, axes_off=False, saturated_pixels=0, vmin=None, vmax=None, no_nans=False, centre_colormap="auto", norm="auto", **kwargs ): """Plot image. Parameters ---------- colorbar : bool, optional If true, a colorbar is plotted for non-RGB images. scalebar : bool, optional If True and the units and scale of the x and y axes are the same a scale bar is plotted. scalebar_color : str, optional A valid MPL color string; will be used as the scalebar color. axes_ticks : {None, bool}, optional If True, plot the axes ticks. If None axes_ticks are only plotted when the scale bar is not plotted. If False the axes ticks are never plotted. axes_off : bool, optional If True, the axes labels are not plotted. saturated_pixels: scalar The percentage of pixels that are left out of the bounds. For example, the low and high bounds of a value of 1 are the 0.5% and 99.5% percentiles. It must be in the [0, 100] range. vmin, vmax : scalar, optional `vmin` and `vmax` are used to normalize luminance data. no_nans : bool, optional If True, set nans to zero for plotting. **kwargs, optional Additional key word arguments passed to matplotlib.imshow() """ if self.signal_plot is not None: self.signal_plot.plot(**kwargs) return super().plot_signal() imf = image.ImagePlot() imf.axes_manager = self.axes_manager imf.data_function = self.signal_data_function imf.title = self.signal_title + " Signal" imf.xaxis, imf.yaxis = self.axes_manager.signal_axes imf.colorbar = colorbar imf.quantity_label = self.quantity_label imf.scalebar = scalebar imf.axes_ticks = axes_ticks imf.axes_off = axes_off imf.vmin, imf.vmax = vmin, vmax imf.saturated_pixels = saturated_pixels imf.no_nans = no_nans imf.scalebar_color = scalebar_color imf.centre_colormap = centre_colormap imf.norm = norm kwargs['data_function_kwargs'] = self.signal_data_function_kwargs imf.plot(**kwargs) self.signal_plot = imf if imf.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.figure.canvas.mpl_connect( 'key_press_event', self.axes_manager.key_navigator) self.navigator_plot.events.closed.connect( self._on_navigator_plot_closing, []) imf.events.closed.connect(self.close_navigator_plot, [])
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_signal(self, colorbar=True, scalebar=True, scalebar_color="white", axes_ticks=None, axes_off=False, saturated_pixels=None, vmin=None, vmax=None, no_nans=False, centre_colormap="auto", norm="auto", min_aspect=0.1, gamma=1.0, linthresh=0.01, linscale=0.1, **kwargs): """Plot image. Parameters ---------- %s %s """ if self.signal_plot is not None: self.signal_plot.plot(**kwargs) return super().plot_signal() imf = image.ImagePlot() imf.axes_manager = self.axes_manager imf.data_function = self.signal_data_function imf.title = self.signal_title + " Signal" imf.xaxis, imf.yaxis = self.axes_manager.signal_axes imf.colorbar = colorbar imf.quantity_label = self.quantity_label imf.scalebar = scalebar imf.axes_ticks = axes_ticks imf.axes_off = axes_off imf.vmin, imf.vmax = vmin, vmax imf.saturated_pixels = saturated_pixels imf.no_nans = no_nans imf.scalebar_color = scalebar_color imf.centre_colormap = centre_colormap imf.min_aspect = min_aspect imf.norm = norm imf.gamma = gamma imf.linthresh = linthresh imf.linscale = linscale kwargs['data_function_kwargs'] = self.signal_data_function_kwargs if "cmap" not in kwargs.keys() or kwargs['cmap'] is None: kwargs["cmap"] = preferences.Plot.cmap_signal imf.plot(**kwargs) self.signal_plot = imf if imf.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.figure.canvas.mpl_connect( 'key_press_event', self.axes_manager.key_navigator) self.navigator_plot.events.closed.connect( self._on_navigator_plot_closing, []) imf.events.closed.connect(self.close_navigator_plot, [])
def plot_signal(self, colorbar=True, scalebar=True, scalebar_color="white", axes_ticks=None, auto_contrast=True, saturated_pixels=0.2, vmin=None, vmax=None, no_nans=False, **kwargs ): """Plot image. Parameters ---------- colorbar : bool, optional If true, a colorbar is plotted for non-RGB images. scalebar : bool, optional If True and the units and scale of the x and y axes are the same a scale bar is plotted. scalebar_color : str, optional A valid MPL color string; will be used as the scalebar color. axes_ticks : {None, bool}, optional If True, plot the axes ticks. If None axes_ticks are only plotted when the scale bar is not plotted. If False the axes ticks are never plotted. auto_contrast : bool, optional If True, the contrast is stretched for each image using the `saturated_pixels` value. Default True saturated_pixels: scalar The percentage of pixels that are left out of the bounds. For example, the low and high bounds of a value of 1 are the 0.5% and 99.5% percentiles. It must be in the [0, 100] range. vmin, vmax : scalar, optional `vmin` and `vmax` are used to normalize luminance data. If `auto_contrast` is True (i.e. default) these values are ignore. no_nans : bool, optional If True, set nans to zero for plotting. **kwargs, optional Additional key word arguments passed to matplotlib.imshow() """ if self.signal_plot is not None: self.signal_plot.plot(**kwargs) return imf = image.ImagePlot() imf.axes_manager = self.axes_manager imf.data_function = self.signal_data_function imf.title = self.signal_title + " Signal" imf.xaxis, imf.yaxis = self.axes_manager.signal_axes imf.colorbar = colorbar imf.scalebar = scalebar imf.axes_ticks = axes_ticks imf.vmin, imf.vmax = vmin, vmax imf.saturated_pixels = saturated_pixels imf.no_nans = no_nans imf.scalebar_color = scalebar_color imf.auto_contrast = auto_contrast imf.plot(**kwargs) self.signal_plot = imf if self.navigator_plot is not None and imf.figure is not None: utils.on_figure_window_close(self.navigator_plot.figure, self.close_navigator_plot) utils.on_figure_window_close( imf.figure, self.close_navigator_plot) self._key_nav_cid = \ self.signal_plot.figure.canvas.mpl_connect( 'key_press_event', self.axes_manager.key_navigator) self._key_nav_cid = \ self.navigator_plot.figure.canvas.mpl_connect( 'key_press_event', self.axes_manager.key_navigator)