Plotting classes and functions#
Classes and functions for plotting spectra and SDFITS data
Core Functions and Classes#
Core plotting functions.
SpecPlot#
Plot a spectrum using matplotlib
- class dysh.plot.specplot.MultiSpanSelector(ax, minspan)[source]#
Bases:
objectMethods
Disconnect all event handlers to prevent memory leaks and dangling references.
get_selected_regions([ignore_incomplete])clear_region
clear_regions
init_selector
on_press
on_select
- disconnect()[source]#
Disconnect all event handlers to prevent memory leaks and dangling references.
- class dysh.plot.specplot.SpectrumPlot(spectrum, **kwargs)[source]#
Bases:
PlotBaseThe SpectrumPlot class is for simple plotting of a
Spectrumusing 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:
- spectrum
Spectrum The spectrum to plot
- spectrum
- Attributes:
Methods
annotate_vline(xval[, text, rotation])Add a single annotated vline to the plot.
clear_overlays([blines, oshows, catalog])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, label, alpha])Add
spectrato the current plot.plot([show_header, select, oshow, oshow_kwargs])Plot the spectrum.
refresh()Refresh the plot
reset()Reset the plot keyword arguments to their defaults.
savefig(file[, hidebuttons])Save the plot
show_catalog_lines([rotation])Overlay spectral lines from various catalogs on the plot, with annotations.
clear_lines
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.
- labelstr
Label for legend.
- alphafloat
Alpha value for the plot. Between 0 and 1.
- 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).
- xaxis_unitstr or
- annotate_vline(xval, text='', rotation=0)[source]#
Add a single annotated vline to the plot. Can be cleared with the “catalog” gid.
- Parameters:
- xvalfloat
X value of the line, in the same units as the plot.
- textstr
Associated text for the vline. Defaults to an empty string.
- rotationfloat
Rotate the text CCW degrees. Default 0.
- clear_overlays(blines=True, oshows=True, catalog=True)[source]#
Clear Overlays from the plot.
- Parameters:
- blinesbool
Remove baseline models overlaid on the plot. Default: True
- oshowsbool
Remove other spectra overlaid on the plot. Default: True
- catalogbool
Remove catalog spectral lines overlaid on the plot. Default: True
- freex()[source]#
Free the X-axis if limits have been set. Resets the limits to be the span of the spectrum.
- freey()[source]#
Free the Y-axis if limits have been set. Autoscales the Y-axis according to your matplotlib configuration.
- oshow(spectra, color=None, linestyle=None, label=None, alpha=None)[source]#
Add
spectrato the current plot.- Parameters:
- spectralist of
dysh.spectra.spectrum.Spectrumordysh.spectra.spectrum.Spectrum Spectra to add to the plot.
- colorlist of valid
matplotlibcolors ormatplotlibcolor Colors for the spectra. There must be one element per spectra.
- linestylelist of valid
matplotliblinestyles ormatplotliblinestyle Linestyles for the spectra. There must be one element per spectra.
- labellist of str
Labels for the spectra. There must be one element per spectra.
- alphalist of float
Alpha values for the spectra, between 0 and 1. There must be one element per spectra.
- spectralist of
- plot(show_header=True, select=True, oshow=None, oshow_kwargs=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.
- oshow_kwargsdict
Dictionary with parameters for
SpectrumPlot.oshow. These include color, linestyle, label, and alpha.
- 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.
- labelstr
Label for legend.
- alphafloat
Alpha value for the plot. Between 0 and 1.
- 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).
- xaxis_unitstr or
ScanPlot#
Plot a spectrum using matplotlib
- class dysh.plot.scanplot.ScanPlot(scanblock_or_scan, **kwargs)[source]#
Bases:
PlotBaseThe ScanPlot class is for simple plotting of a
ScanorScanBlockusing 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_scan
ScanorScanBlock The scan or scanblock to plot.
- **kwargsdict
Plot attribute keyword arguments, see below.
- scanblock_or_scan
- Attributes:
axisThe underlying
Axesobject.
Methods
fmt_scans([abbreviate])Format the scan numbers.
plot([show_header, 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.
write(filename[, avechan, chan, overwrite])Write the current spectrogram as a FITS image.
- Other Parameters:
- spectral_unitstr
The units to use on the frequency axis. Can be ‘MHz’ or ‘GHz’.
- 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
imshownormkeyword, e.g. ‘linear’, ‘log’ etc or a Normalize object.- Parameters:
- normstr | Normalize | None
norm used for the color scale. Default: “None”, for linear scaling.
- write(filename, avechan=1, chan=None, overwrite=False)[source]#
Write the current spectrogram as a FITS image. No WCS is maintained yet. The integrations are in the first axis and the channels in the second.
- Parameters:
- filenamestr
Filename of FITS file to be saved. No default
- avechanint
Averaging number of channels. Only supports averaging by a multiple of the number of channels. Default: 1
- chan[int,int]
If given, it will select this channel range for output. Default: all channels will be selected
- overwriteboolean
Overwrite existing file. Default: False