Plotting classes and functions#

Classes and functions for plotting spectra and SDFITS data

Core Functions and Classes#

Plot a spectrum using matplotlib

class dysh.plot.core.PlotBase(**kwargs)[source]#

Bases: object

This class describes describes the common interface to all Plot classes.

Attributes:
axis

The underlying Axes object

figure

The underlying Figure object

Methods

fmt_scans([abbreviate])

Format the scan numbers.

refresh()

Refresh the plot

savefig(file[, hidebuttons])

Save the plot

property axis#

The underlying Axes object

property figure#

The underlying Figure object

fmt_scans(abbreviate=True)[source]#

Format the scan numbers.

refresh()[source]#

Refresh the plot

savefig(file, hidebuttons=True, **kwargs)[source]#

Save the plot

Parameters:
filestr

The output file name.

hidebuttonsbool

Hide the buttons in the output.

**kwargsdict or key=value pairs

Other arguments to pass to savefig

dysh.plot.core.check_kwargs(known_kwargs, kwargs)[source]#

Check if kwargs are in known_kwargs

SpecPlot#

Plot a spectrum using matplotlib

class dysh.plot.specplot.InteractiveSpanSelector(ax)[source]#

Bases: object

Methods

disconnect()

Disconnect all event handlers to prevent memory leaks and dangling references.

clear_region

clear_regions

get_selected_regions

on_key_press

on_motion

on_press

on_release

onselect

clear_region(event=None)[source]#
clear_regions(event=None)[source]#
disconnect()[source]#

Disconnect all event handlers to prevent memory leaks and dangling references.

get_selected_regions()[source]#
on_key_press(event)[source]#
on_motion(event)[source]#
on_press(event)[source]#
on_release(event)[source]#
onselect(vmin, vmax)[source]#
class dysh.plot.specplot.SpectrumPlot(spectrum, **kwargs)[source]#

Bases: PlotBase

The SpectrumPlot class is for simple plotting of a Spectrum using matplotlib functions. Plots attributes are modified using keywords (**kwargs) described below. SpectrumPlot will attempt to make smart default choices for the plot if no additional keywords are given.

Parameters:
spectrumSpectrum

The spectrum to plot

Attributes:
axis

The underlying Axes object

figure

The underlying Figure object

spectrum

The underlying Spectrum

Methods

clear_lines(gid)

Clears lines with gid from the plot.

clear_overlays([blines, oshows])

Clear Overlays from the plot.

fmt_scans([abbreviate])

Format the scan numbers.

freex()

Free the X-axis if limits have been set.

freexy()

Free the X and Y axes simultaneously.

freey()

Free the Y-axis if limits have been set.

oshow(spectra[, color, linestyle])

Add spectra to the current plot.

plot([show_header, select, oshow])

Plot the spectrum.

refresh()

Refresh the plot

reset()

Reset the plot keyword arguments to their defaults.

savefig(file[, hidebuttons])

Save the plot

default_plot_kwargs

get_selected_regions

Other Parameters:
xaxis_unitstr or Unit

The units to use on the x-axis, e.g. “km/s” to plot velocity.

yaxis_unitstr or Unit

The units to use on the y-axis.

xminfloat

Minimum x-axis value, in xaxis_unit.

xmaxfloat

Maximum x-axis value, in yaxis_unit.

yminfloat

Minimum y-axis value, in xaxis_unit.

ymaxfloat

Maximum y-axis value, in yaxis_unit.

xlabelstr

x-axis label.

ylabelstr

y-axis label.

gridbool

Show a plot grid or not.

figsizetuple

Figure size (see matplotlib).

linewidthfloat

Line width, default: 2.0.

drawstylestr

Line style, default ‘default’.

colorstr

Line color, c also works.

titlestr

Plot title.

vel_framestr

The velocity frame (see VELDEF FITS Keyword).

doppler_convention: str

The velocity convention (see VELDEF FITS Keyword).

clear_lines(gid)[source]#

Clears lines with gid from the plot.

Parameters:
gidstr

Group id for the lines to be cleared.

clear_overlays(blines=True, oshows=True)[source]#

Clear Overlays from the plot.

Parameters:
blinesbool

Remove only baseline models overlaid on the plot. Default: True

default_plot_kwargs()[source]#
freex()[source]#

Free the X-axis if limits have been set. Resets the limits to be the span of the spectrum.

freexy()[source]#

Free the X and Y axes simultaneously. See freex and freey for more details.

freey()[source]#

Free the Y-axis if limits have been set. Autoscales the Y-axis according to your matplotlib configuration.

get_selected_regions()[source]#
oshow(spectra, color=None, linestyle=None)[source]#

Add spectra to the current plot.

Parameters:
spectralist of dysh.spectra.spectrum.Spectrum or dysh.spectra.spectrum.Spectrum

Spectra to add to the plot.

colorlist of valid matplotlib colors or matplotlib color

Colors for the spectra. There must be one element per spectra.

linestylelist of valid matplotlib linestyles or matplotlib linestyle

Linestyles for the spectra. There must be one element per spectra.

plot(show_header=True, select=True, oshow=None, **kwargs)[source]#

Plot the spectrum.

Parameters:
show_headerbool

Show informational header.

selectbool

Allow selecting regions via click and drag.

oshowlist or Spectrum

Spectra to overlay in the plot.

Other Parameters:
xaxis_unitstr or Unit

The units to use on the x-axis, e.g. “km/s” to plot velocity.

yaxis_unitstr or Unit

The units to use on the y-axis.

xminfloat

Minimum x-axis value, in xaxis_unit.

xmaxfloat

Maximum x-axis value, in yaxis_unit.

yminfloat

Minimum y-axis value, in xaxis_unit.

ymaxfloat

Maximum y-axis value, in yaxis_unit.

xlabelstr

x-axis label.

ylabelstr

y-axis label.

gridbool

Show a plot grid or not.

figsizetuple

Figure size (see matplotlib).

linewidthfloat

Line width, default: 2.0.

drawstylestr

Line style, default ‘default’.

colorstr

Line color, c also works.

titlestr

Plot title.

vel_framestr

The velocity frame (see VELDEF FITS Keyword).

doppler_convention: str

The velocity convention (see VELDEF FITS Keyword).

reset()[source]#

Reset the plot keyword arguments to their defaults.

property spectrum#

The underlying Spectrum

ScanPlot#

Plot a spectrum using matplotlib

class dysh.plot.scanplot.ScanPlot(scanblock_or_scan, **kwargs)[source]#

Bases: PlotBase

The ScanPlot class is for simple plotting of a Scan or ScanBlock using matplotlib functions. Plot attributes are modified using keywords (**kwargs) described below. SpectrumPlot will attempt to make smart default choices for the plot if no additional keywords are given.

Parameters:
scanblock_or_scanScan or ScanBlock

The scan or scanblock to plot.

**kwargsdict

Plot attribute keyword arguments, see below.

Attributes:
axis

The underlying Axes object

figure

The underlying Figure object

Methods

fmt_scans([abbreviate])

Format the scan numbers.

plot([spectral_unit])

Plot the scan.

refresh()

Refresh the plot

reset()

Reset the plot keyword arguments to their defaults.

savefig(file[, hidebuttons])

Save the plot

set_clim([vmin, vmax])

Set the vmin and vmax parameters of the image.

set_cmap([cmap])

Set the cmap of the image.

set_interpolation([interpolation])

Set the interpolation of the image.

set_norm([norm])

Set the normalization of the image colormap.

Other Parameters:
spectral_unitstr

The units to use on the frequency axis. Can be ‘MHz’ or ‘GHz’.

plot(spectral_unit=None, **kwargs)[source]#

Plot the scan.

Parameters:
spectral_unitUnit

The units to use on the frequency axis. Default: MHz if below 1 GHz, GHz if above. Otherwise, can be any valid frequency unit.

**kwargsvarious

keyword=value arguments drawn from imshow kwargs. Currently implemented kwargs include cmap, interpolation, vmin, vmax, and norm.

reset()[source]#

Reset the plot keyword arguments to their defaults.

set_clim(vmin=None, vmax=None)[source]#

Set the vmin and vmax parameters of the image.

Parameters:
vminfloat

The minimum value of the color scale. Default None; to autoscale.

vmaxfloat

The maximum value of the color scale. Default None; to autoscale.

set_cmap(cmap='inferno')[source]#

Set the cmap of the image.

Parameters:
cmapstr

cmap used for the color scale. Default: “inferno”.

set_interpolation(interpolation='nearest')[source]#

Set the interpolation of the image.

Parameters:
interpolationstr

Interpolation method. Default: “nearest”.

set_norm(norm=None)[source]#

Set the normalization of the image colormap. Can be any value supported by the imshow norm keyword, e.g. ‘linear’, ‘log’ etc or a Normalize object.

Parameters:
normstr | Normalize | None

norm used for the color scale. Default: “None”, for linear scaling.