Plotting Utilities (photometry.plots)

Plotting utilities.

Code author: Rasmus Handberg <rasmush@phys.au.dk>

photometry.plots.plot_image(image, ax=None, scale='log', cmap=None, origin='lower', xlabel=None, ylabel=None, cbar=None, clabel='Flux ($e^{-}s^{-1}$)', cbar_ticks=None, cbar_ticklabels=None, cbar_pad=None, cbar_size='5%', title=None, percentile=95.0, vmin=None, vmax=None, offset_axes=None, color_bad='k', **kwargs)[source]

Utility function to plot a 2D image.

Parameters:
  • image (2d array) – Image data.

  • ax (matplotlib.pyplot.axes, optional) – Axes in which to plot. Default (None) is to use current active axes.

  • scale (str or astropy.visualization.ImageNormalize object, optional) – Normalization used to stretch the colormap. Options: 'linear', 'sqrt', 'log', 'asinh', 'histeq', 'sinh' and 'squared'. Can also be a astropy.visualization.ImageNormalize object. Default is 'log'.

  • origin (str, optional) – The origin of the coordinate system.

  • xlabel (str, optional) – Label for the x-axis.

  • ylabel (str, optional) – Label for the y-axis.

  • cbar (string, optional) – Location of color bar. Choises are 'right', 'left', 'top', 'bottom'. Default is not to create colorbar.

  • clabel (str, optional) – Label for the color bar.

  • cbar_size (float, optional) – Fractional size of colorbar compared to axes. Default=0.03.

  • cbar_pad (float, optional) – Padding between axes and colorbar.

  • title (str or None, optional) – Title for the plot.

  • percentile (float, optional) – The fraction of pixels to keep in color-trim. If single float given, the same fraction of pixels is eliminated from both ends. If tuple of two floats is given, the two are used as the percentiles. Default=95.

  • cmap (matplotlib colormap, optional) – Colormap to use. Default is the Blues colormap.

  • vmin (float, optional) – Lower limit to use for colormap.

  • vmax (float, optional) – Upper limit to use for colormap.

  • color_bad (str, optional) – Color to apply to bad pixels (NaN). Default is black.

  • kwargs (dict, optional) – Keyword arguments to be passed to matplotlib.pyplot.imshow().

Returns:

Image from returned

by matplotlib.pyplot.imshow().

Return type:

matplotlib.image.AxesImage

Code author: Rasmus Handberg <rasmush@phys.au.dk>

photometry.plots.plot_image_fit_residuals(fig, image, fit, residuals=None, percentile=95.0)[source]

Make a figure with three subplots showing the image, the fit and the residuals. The image and the fit are shown with logarithmic scaling and a common colorbar. The residuals are shown with linear scaling and a separate colorbar.

Parameters:
  • fig (fig object) – Figure object in which to make the subplots.

  • image (2D array) – Image numpy array.

  • fit (2D array) – Fitted image numpy array.

  • residuals (2D array, optional) – Fitted image subtracted from image numpy array.

Returns:

List with Matplotlib subplot axes objects for each subplot.

Return type:

list

photometry.plots.plot_outline(img, ax=None, threshold=0.5, **kwargs)[source]

Plot outline of pixel mask.

Parameters:
  • img (ndarray)

  • ax (matplotlib.pyplot.Axes) – Axes to plot outline into.

  • threshold (float) – If img is not a boolean array, this is used for defining the pixels which should be outlined. Ignored if img is boolean.

  • **kwargs – Additional keywords are passed to matplotlib.pyplot.plot().

Return type:

narray or matplotlib.pyplot.Axes

Code author: Rasmus Handberg <rasmush@phys.au.dk>

photometry.plots.plots_interactive(backend=('QtAgg', 'Qt5Agg', 'MacOSX', 'Qt4Agg', 'Qt5Cairo', 'TkAgg', 'GTK4Agg'))[source]

Change plotting to using an interactive backend.

Parameters:

backend (str or list) – Backend to change to. If not provided, will try different interactive backends and use the first one that works.

Code author: Rasmus Handberg <rasmush@phys.au.dk>

photometry.plots.plots_noninteractive()[source]

Change plotting to using a non-interactive backend, which can e.g. be used on a cluster.

Will set backend to ‘Agg’.

Code author: Rasmus Handberg <rasmush@phys.au.dk>

photometry.plots.save_figure(path, fig=None, fmt='png', **kwargs)[source]

Write current figure to file. Creates directory to place it in if needed.

Keyword arguments to be passed to matplotlib.pyplot.savefig.

Parameters:
  • path (str) – Path where to save figure. If no file extension is provided, the extension of the format is automatically appended.

  • fig (matplotlib.pyplot.Figure) – Figure to save. Default is to save current figure.

  • fmt (str) – Figure file type. Default is 'png'.