APlot — Standardized plot generator.

This module defines the APlot class.

class admit.util.APlot.APlot(pmode=None, ptype=None, figno=None, abspath='')[source]

Basic ADMIT plotter that uses matplotlib calls to create figures.

  • simple parser of extra layout commands on top of general style
  • plotter, scatter or histogram

line x0 y0 x1 y1 ... point x0 y0 ...

Attributes

plotmode Get the plotting mode
plottype Get the plot type

Methods

backend(thebackend)
figure([figno]) set the figure number.
final() final signoff from APlot
getFigure(figno, relative) Get the name of the figure file for given figure number
getThumbnail(figno, relative) Get the name of the thumbnail file for given figure number
hisplot(x[, title, figname, xlab, range, ...]) simple histogram of one column with optional overlayed gaussfit
histogram(columns[, title, figname, xlab, ...]) Simple histogram of one or more columns
makeThumbnail([figno, scale, fig]) Create a thumbnail for a given figure number.
makeUlines(x, y[, noise, title, figname, ...]) simple plotter of multiple columns against one column
makespec(x, y, cutoff, figname[, title, ...]) Plots a spectrum, overlaying known spectral and reference lines.
map1(data[, title, figname, xlab, ylab, ...]) display map; horrible hack, the caller should call np.flipud(np.rot90()) since
multiplotter(x, y[, title, figname, xlab, ...]) Plotter of multiple x against multiple y as traces on same plot.
parse(lines) APlot parser to pass along some matplotlib commands
plotter(x, y[, title, figname, xlab, ylab, ...]) Simple plotter of multiple columns against one column, optionally in histogram style
scatter(x, y[, title, figname, xlab, ylab, ...]) Scatter plot of multiple columns against one column
segplotter(x, y[, title, figname, xlab, ...]) Plotter for spectral line segments.
show() show internals for debugging
summaryspec(stat, spec, pvc, figname[, ...]) Method to plot a summary of all spectra with overlayed id’s.
final()[source]

final signoff from APlot

This would be needed for plotmode=PlotControl.SHOW_AT_END, but this does not seem to work (anymore)

hisplot(x, title=None, figname=None, xlab=None, range=None, bins=80, gauss=None, thumbnail=True)[source]

simple histogram of one column with optional overlayed gaussfit This plot could be merged with histogram()

Returns:None
histogram(columns, title=None, figname=None, xlab=None, xrange=None, ylab='#', bins=80, thumbnail=True)[source]

Simple histogram of one or more columns

Parameters:

columns : numpy array or list of numpy arrays

X axis (abscissa) values

title : str

Title string for plot

figname : str

Root of output file name. An extension matching the plot type will be appended. For instance, for, figname=’fig’ and plottype=PlotControl.PNG, the output file is ‘fig.png’

xlab : str

X axis label

xrange: tuple

X axis range, (xmin,xmax)

ylab : str

Y axis label

bins: int

Number of histogram bins. Default:80

thumbnail : boolean

If True, create a thumbnail when creating an output figure. Thumbnails will have ‘_thumb’ appended for file root. For instance, if the output file is ‘fig.jpg’, the thumbnail will be ‘fig_thumb.jpg’

Returns:

None

makeUlines(x, y, noise=0.0, title=None, figname=None, xlab=None, ylab=None, segments=None, tags=None, thumbnail=True)[source]

simple plotter of multiple columns against one column stolen from atable, allowing some extra bars in the plot for line_id This code should be merged with plotter()

makespec(x, y, cutoff, figname, title='', xlabel='', lines=[], force=[], blends=[], continuum=None, ylabel=None, thumbnail=True, references={}, refline=None, chan=None)[source]

Plots a spectrum, overlaying known spectral and reference lines.

Parameters:

x : list

The x data to plot (usually freq or velocity).

y : list

The spectrum to plot.

cutoff : float or numpy array

A horizontal line at this level will be plotted

figname : str

Root of output file name. An extension matching the plot type will be appended. For instance, for, figname=’fig’ and plottype=PlotControl.PNG, the output file is ‘fig.png’

title : str

The title to put at the top. Default: “”

xlabel : str

Label along the X axis

lines : list

A list of LineData objects, one for each detected transition. The labels and channel ranges are plotted from this information.

force : list

A list of LineData objects for forced lines. The labels and channel ranges are plotted from this information.

blends : list

A list of LineData objects for blended lines. The labels and channel ranges are plotted from this information.

references : dictionary

A dictionary of frequencies and reference line names to be overplotted. This can be useful if you want to plot some well known, but possibly not detected, lines. Default: empty

continuum : list or numpy array?

Matching to the size of the input spectrum, this is the continuum of the spectrum. Default: None

ylabel : str

Label along the Y axis. Default: None (no label)

thumbnail : boolean

If True, create a thumbnail when creating an output figure. Thumbnails will have ‘_thumb’ appended for file root. For instance, if the output file is ‘fig.jpg’, the thumbnail will be ‘fig_thumb.jpg’

references : dict

Dictionary of reference lines to plot. The keys are the frequencies and the values are the labels to place. Default: {}

refline : float

If given, this is the reference frequency for which VLSR = 0.0, the top axis will then be labeled in KM/S. Otherwise the middle of the plot is chosen to be VLSR = 0.0. Default: None (use the center of the spectrum)

chan : list of int, optional

Channel numbers corresponding to x (default: if None, use index number).

Returns:

None

map1(data, title=None, figname=None, xlab=None, ylab=None, range=None, contours=None, cmap='hot', segments=None, circles=None, thumbnail=True, zoom=1, star=None)[source]

display map; horrible hack, the caller should call np.flipud(np.rot90()) since casa and numpy do not have their axes in the same order. We cannot call casa here, since APlot needs to stay casa agnostic. To be resolved.

data: a classic numpy array, i.e. data[ny][nx] where we want data[0][0]
in the lower left corner

segments [x0,x1,y0,y1] star [x,y]

See also casa.viewer() calls in e.g. Moment_AT

multiplotter(x, y, title=None, figname=None, xlab=None, ylab=None, xrange=None, yrange=None, labels=[], thumbnail=True, x2range=None, y2range=None, x2lab=None, y2lab=None)[source]

Plotter of multiple x against multiple y as traces on same plot.

Parameters:

x : list of numpy array

X axis (abscissa) values

y : list of numpy array

Y axis (ordinate) values

title : str

Title string for plot

figname : str

Root of output file name. An extension matching the plot type will be appended. For instance, for, figname=’fig’ and plottype=PlotControl.PNG, the output file is ‘fig.png’

xlab : str

X axis label

ylab : str

Y axis label

xrange : tuple

X axis range (xmin,xmax). Default:None meaning show full range of data

yrange: tuple

Y axis range, (ymin,ymax). Default:None meaning show full range of data

labels : list

labels for the plot traces. In general, there should be one per plot trace.

thumbnail : boolean

If True, create a thumbnail when creating an output figure. Thumbnails will have ‘_thumb’ appended for file root. For instance, if the output file is ‘fig.jpg’, the thumbnail will be ‘fig_thumb.jpg’

x2range: tuple

If given and non-empty, label the upper x axis with a second range. Useful for, e.g. plotting frequency and velocity on the same plot. Default: None, no second x axis

y2range: tuple

If given and non-empty, label the right y axis with a second range. Default: None, no second y axis

x2lab : str

second X axis label

y2lab : str

second Y axis label

Returns:

None

parse(lines)[source]

APlot parser to pass along some matplotlib commands lines : list

A list of matplotlib commands to be added to the current figure. Currently supported:

grid
display a grid on the plot
axis equal
ensure axis scales to be the same, if you want squares and circles to come out as such.
plotter(x, y, title=None, figname=None, xlab=None, ylab=None, xrange=None, yrange=None, segments=None, labels=[], histo=False, thumbnail=True, x2range=None, y2range=None, x2lab=None, y2lab=None)[source]

Simple plotter of multiple columns against one column, optionally in histogram style

Parameters:

x : numpy array

X axis (abscissa) values

y : list of numpy array

Y axis (ordinate) values

title : str

Title string for plot

figname : str

Root of output file name. An extension matching the plot type will be appended. For instance, for, figname=’fig’ and plottype=PlotControl.PNG, the output file is ‘fig.png’

xlab : str

X axis label

ylab : str

Y axis label

xrange : tuple

X axis range (xmin,xmax). Default:None meaning show full range of data

yrange: tuple

Y axis range, (ymin,ymax). Default:None meaning show full range of data

segments : list

list of segment end points pairs for overlaying horizontal segment lines. e.g. [[0,2],[5,6.3],[10.1,14.27]]

labels : list

labels for the plot traces. In general, there should be one per plot trace.

histo : boolean

Histogram style? not implemented yet

thumbnail : boolean

If True, create a thumbnail when creating an output figure. Thumbnails will have ‘_thumb’ appended for file root. For instance, if the output file is ‘fig.jpg’, the thumbnail will be ‘fig_thumb.jpg’

x2range: tuple

If given and non-empty, label the upper x axis with a second range. Useful for, e.g. plotting frequency and velocity on the same plot. Default: None, no second x axis

y2range: tuple

If given and non-empty, label the right y axis with a second range. Default: None, no second y axis

x2lab : str

second X axis label

y2lab : str

second Y axis label

Returns:

None

scatter(x, y, title=None, figname=None, xlab=None, ylab=None, color=None, size=None, cmds=None, thumbnail=True, xrange=None, yrange=None)[source]

Scatter plot of multiple columns against one column

Parameters:

x : numpy array

X axis (abscissa) values

y : numpy array

Y axis (ordinate) values

title : str

Title string for plot

figname : str

Root of output file name. An extension matching the plot type will be appended. For instance, for, figname=’fig’ and plottype=PlotControl.PNG, the output file is ‘fig.png’

xlab : str

X axis label

ylab : str

Y axis label

color : str

Color as defined in matplotlib.Axes.scatter() argument ‘c’.

size : numpy array or scalar

Point size as defined matplotlib.Axes.scatter() argument, It is a size in points^2. It is a scalar or an array of the same length as x and y.

cmds :

add matplot lib commands. See parse()

thumbnail : boolean

If True, create a thumbnail when creating an output figure. Thumbnails will have ‘_thumb’ appended for file root. For instance, if the output file is ‘fig.jpg’, the thumbnail will be ‘fig_thumb.jpg’

xrange : tuple

X axis range (xmin,xmax). Default:None meaning show full range of data

yrange: tuple

Y axis range, (ymin,ymax). Default:None meaning show full range of data

Returns:

None

segplotter(x, y, title='', figname='', xlab='', ylab='', segments=[], cutoff=0.0, continuum=None, thumbnail=True)[source]

Plotter for spectral line segments. Based on plotter, but extended to create a legend.

Parameters:

x : numpy array

X axis (abscissa) values

y : numpy array

Y axis (ordinate) values

title : str

Title string for plot

figname : str

Root of output file name. An extension matching the plot type will be appended. For instance, for, figname=’fig’ and plottype=PlotControl.PNG, the output file is ‘fig.png’

xlab : str

X axis label

ylab : str

Y axis label

segments : list

list of segment end points pairs for overlaying horizontal segment lines. e.g. [[0,2],[5,6.3],[10.1,14.27]]

cutoff : float or list of floats

y-axis value(s) at which to draw the cutoff-level indicator (horizontal line)

continuum : float or list of floats

y-axis value(s) at which to draw the continuum “Mean/Baseline” indicator (horizontal line)

thumbnail : boolean

If True, create a thumbnail when creating an output figure. Thumbnails will have ‘_thumb’ appended for file root. For instance, if the output file is ‘fig.jpg’, the thumbnail will be ‘fig_thumb.jpg’

Returns:

None

summaryspec(stat, spec, pvc, figname, lines=[], thumbnail=True, force=[])[source]

Method to plot a summary of all spectra with overlayed id’s. All spectra are in S/N units.

Parameters:

stat : list

List of Spectrum class holding the CubeStats based spectrum

spec : list

List of Spectrum classes, each holding the CubeSpectrum based spectrum

pvc : Spectrum instance

Instance of Spectrum class holding the PVCorr based spectrum

figname : str

The name of the output figure

lines : list

List of LineData objects, one for each detected transition or segment

thumbnail : bool

If True then generate a thumbnail of the image. Default: True

force : list

List of LineData objects, one for each forced line id. Default: []

Returns:

None