Table Of Contents

Previous topic

Creating subplots

This Page

Complete API

Initialization

class aplpy.FITSFigure(data, hdu=0, figure=None, subplot=None, downsample=False, north=False, convention=None, dimensions=[0, 1], slices=[], auto_refresh=True, **kwargs)

A class for plotting FITS files.

__init__(data, hdu=0, figure=None, subplot=None, downsample=False, north=False, convention=None, dimensions=[0, 1], slices=[], auto_refresh=True, **kwargs)

Create a FITSFigure instance

Required arguments:

data: [ string | pyfits.PrimaryHDU | pyfits.ImageHDU | pywcs.WCS | np.ndarray ]
Either the filename of the FITS file to open, a pyfits PrimaryHDU or ImageHDU object, or a pywcs WCS object. It is also possible to specify the filename of an RGB image tagged with AVM meta-data.

Optional Keyword Arguments:

hdu: [ integer ]
By default, the image in the primary HDU is read in. If a different HDU is required, use this argument.
figure: [ matplotlib figure() instance ]
If specified, a subplot will be added to this existing matplotlib figure() instance, rather than a new figure being created from scratch.
subplot: [ list of four floats ]
If specified, a subplot will be added at this position. The list should contain [xmin, ymin, dx, dy] where xmin and ymin are the position of the bottom left corner of the subplot, and dx and dy are the width and height of the subplot respectively. These should all be given in units of the figure width and height. For example, [0.1, 0.1, 0.8, 0.8] will almost fill the entire figure, leaving a 10 percent margin on all sides.
downsample: [ integer ]
If this option is specified, the image will be downsampled by a factor downsample when reading in the data.
north: [ True | False ]
Whether to rotate the image so that the North Celestial Pole is up. Note that this option requires Montage to be installed.
convention: [ string ]
This is used in cases where a FITS header can be interpreted in multiple ways. For example, for files with a -CAR projection and CRVAL2=0, this can be set to ‘wells’ or ‘calabretta’ to choose the appropriate convention.
dimensions: [ tuple or list]
The index of the axes to use if the data has more than three dimensions.
slices: [ tuple or list ]
If a FITS file with more than two dimensions is specified, then these are the slices to extract. If all extra dimensions only have size 1, then this is not required.
auto_refresh: [ True | False ]
Whether to refresh the figure automatically every time a plotting method is called. This can also be set using the set_auto_refresh method.

Any additional arguments are passed on to matplotlib’s Figure() class. For example, to set the figure size, use the figsize=(xsize, ysize) argument (where xsize and ysize are in inches). For more information on these additional arguments, see the Optional keyword arguments section in the documentation for Figure

General routines

FITSFigure.show_grayscale(vmin=None, vmid=None, vmax=None, pmin=0.25, pmax=99.75, stretch='linear', exponent=2, invert='default', smooth=None, kernel='gauss', aspect='equal', interpolation='nearest')

Show a grayscale image of the FITS file

Optional Keyword Arguments:

vmin: [ None | float ]
Minimum pixel value to use for the grayscale. If set to None, the minimum pixel value is determined using pmin (default).
vmax: [ None | float ]
Maximum pixel value to use for the grayscale. If set to None, the maximum pixel value is determined using pmax (default).
pmin: [ float ]
Percentile value used to determine the minimum pixel value to use for the grayscale if vmin is set to None. The default value is 0.25%.
pmax: [ float ]
Percentile value used to determine the maximum pixel value to use for the grayscale if vmax is set to None. The default value is 99.75%.
stretch: [ ‘linear’ | ‘log’ | ‘sqrt’ | ‘arcsinh’ | ‘power’ ]
The stretch function to use
vmid: [ None | float ]
Baseline value used for the log and arcsinh stretches. If set to None, this is set to zero for log stretches and to vmin - (vmax - vmin) / 30. for arcsinh stretches
exponent: [ float ]
If stretch is set to ‘power’, this is the exponent to use
invert: [ True | False ]
Whether to invert the grayscale or not. The default is False, unless set_theme is used, in which case the default depends on the theme.
smooth: [ integer | tuple ]
Default smoothing scale is 3 pixels across. User can define whether they want an NxN kernel (integer), or NxM kernel (tuple). This argument corresponds to the ‘gauss’ and ‘box’ smoothing kernels.
kernel: [ ‘gauss’ | ‘box’ | numpy.array]
Default kernel used for smoothing is ‘gauss’. The user can specify if they would prefer ‘gauss’, ‘box’, or a custom kernel. All kernels are normalized to ensure flux retention.
aspect: [‘auto’, ‘equal’]
Whether to change the aspect ratio of the image to match that of the axes (‘auto’) or to change the aspect ratio of the axes to match that of the data (‘equal’; default)
interpolation: [ string ]
The type of interpolation to use for the image. The default is ‘nearest’. Other options include ‘none’ (no interpolation, meaning that if exported to a postscript file, the grayscale will be output at native resolution irrespective of the dpi setting), ‘bilinear’, ‘bicubic’, and many more (see the matplotlib documentation for imshow).
FITSFigure.hide_grayscale(*args, **kwargs)
FITSFigure.show_colorscale(vmin=None, vmid=None, vmax=None, pmin=0.25, pmax=99.75, stretch='linear', exponent=2, cmap='default', smooth=None, kernel='gauss', aspect='equal', interpolation='nearest')

Show a colorscale image of the FITS file

Optional Keyword Arguments:

vmin: [ None | float ]
Minimum pixel value to use for the colorscale. If set to None, the minimum pixel value is determined using pmin (default).
vmax: [ None | float ]
Maximum pixel value to use for the colorscale. If set to None, the maximum pixel value is determined using pmax (default).
pmin: [ float ]
Percentile value used to determine the minimum pixel value to use for the colorscale if vmin is set to None. The default value is 0.25%.
pmax: [ float ]
Percentile value used to determine the maximum pixel value to use for the colorscale if vmax is set to None. The default value is 99.75%.
stretch: [ ‘linear’ | ‘log’ | ‘sqrt’ | ‘arcsinh’ | ‘power’ ]
The stretch function to use
vmid: [ None | float ]
Baseline value used for the log and arcsinh stretches. If set to None, this is set to zero for log stretches and to vmin - (vmax - vmin) / 30. for arcsinh stretches
exponent: [ float ]
If stretch is set to ‘power’, this is the exponent to use
cmap: [ string ]
The name of the colormap to use
smooth: [ integer | tuple ]
Default smoothing scale is 3 pixels across. User can define whether they want an NxN kernel (integer), or NxM kernel (tuple). This argument corresponds to the ‘gauss’ and ‘box’ smoothing kernels.
kernel: [ ‘gauss’ | ‘box’ | numpy.array]
Default kernel used for smoothing is ‘gauss’. The user can specify if they would prefer ‘gauss’, ‘box’, or a custom kernel. All kernels are normalized to ensure flux retention.
aspect: [‘auto’, ‘equal’]
Whether to change the aspect ratio of the image to match that of the axes (‘auto’) or to change the aspect ratio of the axes to match that of the data (‘equal’; default)
interpolation: [ string ]
The type of interpolation to use for the image. The default is ‘nearest’. Other options include ‘none’ (no interpolation, meaning that if exported to a postscript file, the colorscale will be output at native resolution irrespective of the dpi setting), ‘bilinear’, ‘bicubic’, and many more (see the matplotlib documentation for imshow).
FITSFigure.hide_colorscale()
FITSFigure.show_rgb(filename=None, interpolation='nearest', vertical_flip=False, horizontal_flip=False, flip=False)

Show a 3-color image instead of the FITS file data

Optional Arguments:

filename
The 3-color image should have exactly the same dimensions as the FITS file, and will be shown with exactly the same projection. If FITSFigure was initialized with an AVM-tagged RGB image, the filename is not needed here.
vertical_flip: [ True | False ]
Whether to vertically flip the RGB image
horizontal_flip: [ True | False ]
Whether to horizontally flip the RGB image
FITSFigure.recenter(x, y, radius=None, width=None, height=None)

Center the image on a given position and with a given radius

Required Arguments:

x, y: [ float ]
Coordinates to center on

Optional Keyword Arguments:

Either the radius or width/heigh arguments should be specified.

radius: [ float ]
Radius of the region to view. This produces a square plot.
width: [ float ]
Width of the region to view. This should be given in conjunction with the height argument.
height: [ float ]
Height of the region to view. This should be given in conjunction with the width argument.
FITSFigure.show_contour(data, hdu=0, layer=None, levels=5, filled=False, cmap=None, colors=None, returnlevels=False, convention=None, dimensions=[0, 1], slices=[], smooth=None, kernel='gauss', overlap=False, **kwargs)

Overlay contours on the current plot

Required Arguments:

data: [ string | pyfits PrimaryHDU | pyfits ImageHDU ]
Either the filename of the FITS file to open, or a pyfits PrimaryHDU or ImageHDU instance.

Optional Keyword Arguments:

hdu: [ integer ]
By default, the image in the primary HDU is read in. If a different HDU is required, use this argument.
layer: [ string ]
The name of the contour layer. This is useful for giving custom names to layers (instead of contour_set_n) and for replacing existing layers.
levels: [ int | list ]
This can either be the number of contour levels to compute (if an integer is provided) or the actual list of contours to show (if a list of floats is provided)
filled: [ True | False ]
Whether to show filled or line contours
cmap: [ string ]
The colormap to use for the contours
colors: [ string | tuple of strings ]
If a single string is provided, all contour levels will be shown in this color. If a tuple of strings is provided, each contour will be colored according to the corresponding tuple element.
returnlevels: [ True | False ]
Whether to return the list of contours to the caller.
convention: [ string ]
This is used in cases where a FITS header can be interpreted in multiple ways. For example, for files with a -CAR projection and CRVAL2=0, this can be set to ‘wells’ or ‘calabretta’ to choose the appropriate convention.
dimensions: [ tuple or list]
The index of the axes to use if the data has more than three dimensions.
slices: [ tuple or list ]
If a FITS file with more than two dimensions is specified, then these are the slices to extract. If all extra dimensions only have size 1, then this is not required.
smooth: [ integer | tuple ]
Default smoothing scale is 3 pixels across. User can define whether they want an NxN kernel (integer), or NxM kernel (tuple). This argument corresponds to the ‘gauss’ and ‘box’ smoothing kernels.
kernel: [ ‘gauss’ | ‘box’ | numpy.array]
Default kernel used for smoothing is ‘gauss’. The user can specify if they would prefer ‘gauss’, ‘box’, or a custom kernel. All kernels are normalized to ensure flux retention.
overlap [ True | False ]
Whether to include only contours that overlap with the image area. This significantly speeds up the drawing of contours and reduces file size when using a file for the contours covering a much larger area than the image.

Additional keyword arguments (such as alpha, linewidths, or linestyles) will be passed on directly to matplotlib’s contour or contourf methods. For more information on these additional arguments, see the Optional keyword arguments sections in the documentation for contour and contourf.

FITSFigure.save(filename, dpi=None, transparent=False, adjust_bbox=True, max_dpi=300)

Save the current figure to a file

Required arguments:

filename: [ string ]
The name of the file to save the plot to. This can be for example a PS, EPS, PDF, PNG, JPEG, or SVG file.

Optional Keyword Arguments:

dpi: [ float ]
The output resolution, in dots per inch. If the output file is a vector graphics format (such as PS, EPS, PDF or SVG) only the image itself will be rasterized. If the output is a PS or EPS file and no dpi is specified, the dpi is automatically calculated to match the resolution of the image. If this value is larger than max_dpi, then dpi is set to max_dpi.
transparent: [ True | False ]
Whether to preserve transparency
adjust_bbox: [ True | False ]
Auto-adjust the bounding box for the output
max_dpi: [ float ]
The maximum resolution to output images at. If no maximum is wanted, enter None or 0.

Labels

FITSFigure.add_label(x, y, text, relative=False, color='black', family=None, style=None, variant=None, stretch=None, weight=None, size=None, fontproperties=None, horizontalalignment='center', verticalalignment='center', layer=None, **kwargs)

Add a text label

Required Arguments:

x, y: [ float ]
Coordinates of the text label
text: [ string ]
The label

Optional Keyword Arguments:

relative: [ True | False ]
Whether the coordinates are to be interpreted as world coordinates (e.g. RA/Dec or longitude/latitude), or coordinates relative to the axes (where 0.0 is left or bottom and 1.0 is right or top).
family:
The family of the font to use. This can either be a generic font family name, either ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, or ‘monospace’, or a list of font names in decreasing order of priority.
style:
The font style. This can be ‘normal’, ‘italic’ or ‘oblique’.
variant:
The font variant. This can be ‘normal’ or ‘small-caps’
stretch:
The stretching (spacing between letters) for the font. This can either be a numeric value in the range 0-1000 or one of ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’ or ‘ultra-expanded’.
weight:
The weight (or boldness) of the font. This can either be a numeric value in the range 0-1000 or one of ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’.
size:
The size of the font. This can either be a numeric value (e.g. 12), giving the size in points, or one of ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, or ‘xx-large’.

Shapes

FITSFigure.show_markers(xw, yw, layer=False, **kwargs)

Overlay markers on the current plot.

Required arguments:

xw: [ list | numpy.ndarray ]
The x postions of the markers (in world coordinates)
yw: [ list | numpy.ndarray ]
The y positions of the markers (in world coordinates)

Optional Keyword Arguments:

layer: [ string ]
The name of the scatter layer. This is useful for giving custom names to layers (instead of marker_set_n) and for replacing existing layers.

Additional keyword arguments (such as marker, facecolor, edgecolor, alpha, or linewidth) will be passed on directly to matplotlib’s scatter method. For more information on these additional arguments, see the Optional keyword arguments sections in the documentation for scatter.

FITSFigure.show_circles(xw, yw, radius, layer=False, zorder=None, **kwargs)

Overlay circles on the current plot.

Required arguments:

xw: [ list | numpy.ndarray ]
The x postions of the circles (in world coordinates)
yw: [ list | numpy.ndarray ]
The y positions of the circles (in world coordinates)
radius: [integer | float | list | numpy.ndarray ]
The radii of the circles (in world coordinates)

Optional Keyword Arguments:

layer: [ string ]
The name of the circle layer. This is useful for giving custom names to layers (instead of circle_set_n) and for replacing existing layers.

Additional keyword arguments (such as facecolor, edgecolor, alpha, or linewidth) can be used to control the appearance of the circles, which are instances of the matplotlib Circle class. For more information on available arguments, see Circle.

FITSFigure.show_ellipses(xw, yw, width, height, angle=0, layer=False, zorder=None, **kwargs)

Overlay ellipses on the current plot.

Required arguments:

xw: [ list | numpy.ndarray ]
The x postions of the ellipses (in world coordinates)
yw: [ list | numpy.ndarray ]
The y positions of the ellipses (in world coordinates)
width: [integer | float | list | numpy.ndarray ]
The width of the ellipse (in world coordinates)
height: [integer | float | list | numpy.ndarray ]
The height of the ellipse (in world coordinates)

Optional Keyword Arguments:

angle: [integer | float | list | numpy.ndarray ]
rotation in degrees (anti-clockwise). Default angle is 0.0.
layer: [ string ]
The name of the ellipse layer. This is useful for giving custom names to layers (instead of ellipse_set_n) and for replacing existing layers.

Additional keyword arguments (such as facecolor, edgecolor, alpha, or linewidth) can be used to control the appearance of the ellipses, which are instances of the matplotlib Ellipse class. For more information on available arguments, see Ellipse.

FITSFigure.show_rectangles(xw, yw, width, height, layer=False, zorder=None, **kwargs)

Overlay rectangles on the current plot.

Required arguments:

xw: [ list | numpy.ndarray ]
The x postions of the rectangles (in world coordinates)
yw: [ list | numpy.ndarray ]
The y positions of the rectangles (in world coordinates)
width: [integer | float | list | numpy.ndarray ]
The width of the rectangle (in world coordinates)
height: [integer | float | list | numpy.ndarray ]
The height of the rectangle (in world coordinates)

Optional Keyword Arguments:

layer: [ string ]
The name of the rectangle layer. This is useful for giving custom names to layers (instead of rectangle_set_n) and for replacing existing layers.

Additional keyword arguments (such as facecolor, edgecolor, alpha, or linewidth) can be used to control the appearance of the rectangles, which are instances of the matplotlib Rectangle class. For more information on available arguments, see Rectangle.

FITSFigure.show_lines(line_list, layer=False, zorder=None, **kwargs)

Overlay lines on the current plot.

Required arguments:

line_list: [ list ]
A list of one or more 2xN numpy arrays which contain the [x, y] positions of the vertices in world coordinates.

Optional Keyword Arguments:

layer: [ string ]
The name of the line(s) layer. This is useful for giving custom names to layers (instead of line_set_n) and for replacing existing layers.

Additional keyword arguments (such as color, offsets, cmap, or linewidth) can be used to control the appearance of the lines, which is an instances of the matplotlib LineCollection class. For more information on available arguments, see LineCollection.

FITSFigure.show_polygons(polygon_list, layer=False, zorder=None, **kwargs)

Overlay polygons on the current plot.

Required arguments:

polygon_list: [ list or tuple ]
A list of one or more 2xN or Nx2 Numpy arrays which contain the [x, y] positions of the vertices in world coordinates. Note that N should be greater than 2.

Optional Keyword Arguments:

layer: [ string ]
The name of the circle layer. This is useful for giving custom names to layers (instead of circle_set_n) and for replacing existing layers.

Additional keyword arguments (such as facecolor, edgecolor, alpha, or linewidth) can be used to control the appearance of the circles, which are instances of the matplotlib Polygon class. For more information on available arguments, see Polygon.

FITSFigure.show_arrows(x, y, dx, dy, width='auto', head_width='auto', head_length='auto', layer=False, zorder=None, **kwargs)

Overlay arrows on the current plot.

Required arguments:

x, y, dx, dy: [ float | list | array ]
Origin and displacement of the arrows in world coordinates. These can either be scalars to plot a single arrow, or lists or arrays to plot multiple arrows.

Optional Keyword Arguments:

width: [ float ]
The width of the arrow body, in pixels (default: 2% of the arrow length)
head_width: [ float ]
The width of the arrow head, in pixels (default: 5% of the arrow length)
head_length: [ float ]
The length of the arrow head, in pixels (default: 5% of the arrow length)
layer: [ string ]
The name of the arrow(s) layer. This is useful for giving custom names to layers (instead of line_set_n) and for replacing existing layers.

Additional keyword arguments (such as color, offsets, cmap, or linewidth) can be used to control the appearance of the arrows, which is an instances of the matplotlib FancyArrow class. For more information on available arguments, see FancyArrow.

Layers

FITSFigure.list_layers()

Print a list of layers to standard output

FITSFigure.remove_layer(layer, raise_exception=True)

Remove a layer

Required Arguments:

layer: [ string ]
The name of the layer to remove
FITSFigure.hide_layer(layer, raise_exception=True)

Hide a layer

This differs from remove_layer in that if a layer is hidden it can be shown again using show_layer.

Required Arguments:

layer: [ string ]
The name of the layer to hide
FITSFigure.show_layer(layer, raise_exception=True)

Show a layer

This shows a layer previously hidden with hide_layer

Required Arguments:

layer: [ string ]
The name of the layer to show
FITSFigure.get_layer(layer, raise_exception=True)

Return a layer object

Required Arguments:

layer: [ string ]
The name of the layer to return

Coordinates

FITSFigure.world2pixel(xw, yw)

Convert world to pixel coordinates

Required arguments:

xw: [ scalar | list | numpy array ]
x world coordinate
yw: [ scalar | list | numpy array ]
y world coordinate

Returns the pixel coordinates as a tuple of scalars, lists, or numpy arrays depending on the input

FITSFigure.pixel2world(xp, yp)

Convert pixel to world coordinates

Required arguments:

xp: [ scalar | list | numpy array ]
x pixel coordinate
yp: [ scalar | list | numpy array ]
y pixel coordinate

Returns the world coordinates as a tuple of scalars, lists, or numpy arrays depending on the input

Frame

class aplpy.frame.Frame(parent)
set_color(color)

Set color of the frame

Required arguments:

color:
The color to use for the frame.
set_linewidth(linewidth)

Set line width of the frame

Required arguments:

linewidth:
The linewidth to use for the frame.

Colorbar

FITSFigure.add_colorbar(*args, **kwargs)

Add a colorbar to the current figure

Once this method has been run, a colorbar attribute becomes available, and can be used to control the aspect of the colorbar:

>>> f = aplpy.FITSFigure(...)
>>> ...
>>> f.add_colorbar()
>>> f.colorbar.set_width(0.3)
>>> f.colorbar.set_location('top')
>>> ...
FITSFigure.remove_colorbar()

Removes the colorbar from the current figure

class aplpy.colorbar.Colorbar(parent)
set_box(box, box_orientation='vertical')

Set the box within which to place the colorbar. This should be in the form [xmin, ymin, dx, dy] and be in relative figure units. The orientation of the colorbar within the box can be controlled with the box_orientation argument.

set_font(family=None, style=None, variant=None, stretch=None, weight=None, size=None, fontproperties=None)

Set the font of the tick labels

Optional Keyword Arguments:

family:
The family of the font to use. This can either be a generic font family name, either ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, or ‘monospace’, or a list of font names in decreasing order of priority.
style:
The font style. This can be ‘normal’, ‘italic’ or ‘oblique’.
variant:
The font variant. This can be ‘normal’ or ‘small-caps’
stretch:
The stretching (spacing between letters) for the font. This can either be a numeric value in the range 0-1000 or one of ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’ or ‘ultra-expanded’.
weight:
The weight (or boldness) of the font. This can either be a numeric value in the range 0-1000 or one of ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’.
size:
The size of the font. This can either be a numeric value (e.g. 12), giving the size in points, or one of ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, or ‘xx-large’.

Default values are set by matplotlib or previously set values if set_font has already been called. Global default values can be set by editing the matplotlibrc file.

set_frame_color(color)

Set the color of the colorbar frame, in points

set_frame_linewidth(linewidth)

Set the linewidth of the colorbar frame, in points

set_labels(labels)

Set whether to show numerical labels.

set_location(location)

Set the location of the colorbar. Should be one of ‘left’, ‘right’, ‘top’, ‘bottom’.

set_pad(pad)

Set the spacing between the colorbar and the image relative to the canvas size.

set_ticks(ticks)

Set the position of the ticks on the colorbar.

set_width(width)

Set the width of the colorbar relative to the canvas size.

show(location='right', width=0.2, pad=0.05, ticks=None, labels=True, box=None, box_orientation='vertical')

Show a colorbar on the side of the image.

Optional Keyword Arguments:

location: [ string ]
Where to place the colorbar. Should be one of ‘left’, ‘right’, ‘top’, ‘bottom’.
width: [ float ]
The width of the colorbar relative to the canvas size.
pad: [ float ]
The spacing between the colorbar and the image relative to the canvas size.
ticks: [ None or list ]
The position of the ticks on the colorbar.
labels: [ True or False ]
Whether to show numerical labels.
box: [ list ]
A custom box within which to place the colorbar. This should be in the form [xmin, ymin, dx, dy] and be in relative figure units. This overrides the location argument.
box_orientation [ str ]
The orientation of the colorbar within the box. Can be ‘horizontal’ or ‘vertical’

Coordinate Grid

FITSFigure.add_grid(*args, **kwargs)

Add a coordinate to the current figure

Once this method has been run, a grid attribute becomes available, and can be used to control the aspect of the grid:

>>> f = aplpy.FITSFigure(...)
>>> ...
>>> f.add_grid()
>>> f.grid.set_color('white')
>>> f.grid.set_alpha(0.5)
>>> ...
FITSFigure.remove_grid()

Removes the grid from the current figure

class aplpy.grid.Grid(parent)
set_alpha(alpha)

Set the alpha (transparency) of the grid lines

Required Arguments:

alpha: [ float ]
The alpha value of the grid. This should be a floating point value between 0 and 1, where 0 is completely transparent, and 1 is completely opaque.
set_color(color)

Set the color of the grid lines

Required Arguments:

color: [ string ]
The color of the grid lines
set_xspacing(xspacing)

Set the grid line spacing in the longitudinal direction

Required Arguments:

xspacing: [ float | ‘tick’ ]
The spacing in the longitudinal direction. To set the spacing to be the same as the ticks, set this to ‘tick’
set_yspacing(yspacing)

Set the grid line spacing in the latitudinal direction

Required Arguments:

yspacing: [ float | ‘tick’ ]
The spacing in the latitudinal direction. To set the spacing to be the same as the ticks, set this to ‘tick’

Scalebar

FITSFigure.add_scalebar(length, *args, **kwargs)

Add a scalebar to the current figure

Once this method has been run, a scalebar attribute becomes available, and can be used to control the aspect of the scalebar:

>>> f = aplpy.FITSFigure(...)
>>> ...
>>> f.add_scalebar(0.01) # length has to be specified
>>> f.scalebar.set_label('100 AU')
>>> ...
FITSFigure.remove_scalebar()

Removes the scalebar from the current figure

class aplpy.overlays.ScaleBar(parent)
hide()

Hide the scalebar.

set(**kwargs)

Modify the scalebar and scalebar properties. All arguments are passed to the matplotlib Rectangle and Text classes. See the matplotlib documentation for more details. In cases where the same argument exists for the two objects, the argument is passed to both the Text and Rectangle instance.

set_alpha(alpha)

Set the alpha value (transparency). This should be a floating point value between 0 and 1.

set_color(color)

Set the label and scalebar color.

set_corner(corner)

Set where to place the scalebar. Acceptable values are ‘left’, ‘right’, ‘top’, ‘bottom’, ‘top left’, ‘top right’, ‘bottom left’ (default), and ‘bottom right’.

set_font(family=None, style=None, variant=None, stretch=None, weight=None, size=None, fontproperties=None)

Set the font of the tick labels

Optional Keyword Arguments:

common: family, style, variant, stretch, weight, size, fontproperties

Default values are set by matplotlib or previously set values if set_font has already been called. Global default values can be set by editing the matplotlibrc file.

set_frame(frame)

Set whether to display a frame around the scalebar.

set_label(label)

Set the label of the scale bar.

set_length(length)

Set the length of the scale bar.

set_linestyle(linestyle)

Set the linestyle of the scalebar. Should be one of ‘solid’, ‘dashed’, ‘dashdot’, or ‘dotted’.

set_linewidth(linewidth)

Set the linewidth of the scalebar, in points.

show(length, label=None, corner='bottom right', frame=False, borderpad=0.4, pad=0.5, **kwargs)

Overlay a scale bar on the image.

Required Arguments:

length:[ float ]
The length of the scalebar

Optional Keyword Arguments:

label: [ string ]
Label to place below the scalebar
corner: [ integer ]
Where to place the scalebar. Acceptable values are:, ‘left’, ‘right’, ‘top’, ‘bottom’, ‘top left’, ‘top right’, ‘bottom left’ (default), ‘bottom right’
frame: [ True | False ]
Whether to display a frame behind the scalebar (default is False)

Advanced:

Additional arguments are passed to the matplotlib Rectangle and Text classes. See the matplotlib documentation for more details. In cases where the same argument exists for the two objects, the argument is passed to both the Text and Rectangle instance.

Beam

FITSFigure.add_beam(*args, **kwargs)

Add a beam to the current figure

Once this method has been run, a beam attribute becomes available, and can be used to control the aspect of the beam:

>>> f = aplpy.FITSFigure(...)
>>> ...
>>> f.add_beam()
>>> f.beam.set_color('white')
>>> f.beam.set_hatch('+')
>>> ...

If more than one beam is added, the beam object becomes a list. In this case, to control the aspect of one of the beams, you will need tp specify the beam index:

>>> ...
>>> f.beam[2].set_hatch('/')
>>> ...
FITSFigure.remove_beam(beam_index=None)

Removes the beam from the current figure. If more than one beam is present, the index of the beam should be specified using beam_index=

class aplpy.overlays.Beam(parent)
hide()

Hide the beam

set(**kwargs)

Modify the beam properties. All arguments are passed to the matplotlib Ellipse classe. See the matplotlib documentation for more details.

set_alpha(alpha)

Set the alpha value (transparency). This should be a floating point value between 0 and 1.

set_angle(angle)

Set the position angle of the beam on the sky in degrees.

set_borderpad(borderpad)

Set the amount of padding within the beam object, relative to the canvas size.

set_color(color)

Set the beam color.

set_corner(corner)

Set the beam location. Acceptable values are ‘left’, ‘right’, ‘top’, ‘bottom’, ‘top left’, ‘top right’, ‘bottom left’ (default), and ‘bottom right’.

set_edgecolor(edgecolor)

Set the color for the edge of the beam.

set_facecolor(facecolor)

Set the color for the interior of the beam.

set_frame(frame)

Set whether to display a frame around the beam.

set_hatch(hatch)

Set the hatch pattern. This should be one of ‘/’, ‘’, ‘|’, ‘-‘, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, or ‘*’.

set_linestyle(linestyle)

Set the line style for the edge of the beam. This should be one of ‘solid’, ‘dashed’, ‘dashdot’, or ‘dotted’.

set_linewidth(linewidth)

Set the line width for the edge of the beam, in points.

set_major(major)

Set the major axis of the beam, in degrees.

set_minor(minor)

Set the minor axis of the beam, in degrees.

set_pad(pad)

Set the amount of padding between the beam object and the image corner/edge, relative to the canvas size.

show(major='BMAJ', minor='BMIN', angle='BPA', corner='bottom left', frame=False, borderpad=0.4, pad=0.5, **kwargs)

Display the beam shape and size for the primary image

By default, this method will search for the BMAJ, BMIN, and BPA keywords in the FITS header to set the major and minor axes and the position angle on the sky.

Optional Keyword Arguments:

major: [ float ]
Major axis of the beam in degrees (overrides BMAJ if present)
minor: [ float ]
Minor axis of the beam in degrees (overrides BMIN if present)
angle: [ float ]
Position angle of the beam on the sky in degrees (overrides BPA if present) in the anticlockwise direction.
corner: [ integer ]
The beam location. Acceptable values are ‘left’, ‘right’, ‘top’, ‘bottom’, ‘top left’, ‘top right’, ‘bottom left’ (default), and ‘bottom right’.
frame: [ True | False ]
Whether to display a frame behind the beam (default is False)

Advanced:

Additional arguments are passed to the matplotlib Ellipse classe. See the matplotlib documentation for more details.

Axis labels

class aplpy.axis_labels.AxisLabels(parent)
hide()

Hide the x- and y-axis labels

hide_x()

Hide the x-axis label

hide_y()

Hide the y-axis label

set_font(family=None, style=None, variant=None, stretch=None, weight=None, size=None, fontproperties=None)

Set the font of the axis labels

Optional Keyword Arguments:

family:
The family of the font to use. This can either be a generic font family name, either ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, or ‘monospace’, or a list of font names in decreasing order of priority.
style:
The font style. This can be ‘normal’, ‘italic’ or ‘oblique’.
variant:
The font variant. This can be ‘normal’ or ‘small-caps’
stretch:
The stretching (spacing between letters) for the font. This can either be a numeric value in the range 0-1000 or one of ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’ or ‘ultra-expanded’.
weight:
The weight (or boldness) of the font. This can either be a numeric value in the range 0-1000 or one of ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’.
size:
The size of the font. This can either be a numeric value (e.g. 12), giving the size in points, or one of ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, or ‘xx-large’.

Default values are set by matplotlib or previously set values if set_font has already been called. Global default values can be set by editing the matplotlibrc file.

set_xpad(pad)

Set the x-axis label displacement, in points

set_xposition(position)

Set the position of the x-axis label (‘top’ or ‘bottom’)

set_xtext(label)

Set the x-axis label text

set_ypad(pad)

Set the y-axis label displacement, in points

set_yposition(position)

Set the position of the y-axis label (‘left’ or ‘right’)

set_ytext(label)

Set the y-axis label text

show()

Show the x- and y-axis labels

show_x()

Show the x-axis label

show_y()

Show the y-axis label

Tick labels

class aplpy.labels.TickLabels(parent)
hide()

Hide the x- and y-axis tick labels

hide_x()

Hide the x-axis tick labels

hide_y()

Hide the y-axis tick labels

set_font(family=None, style=None, variant=None, stretch=None, weight=None, size=None, fontproperties=None)

Set the font of the tick labels

Optional Keyword Arguments:

family:
The family of the font to use. This can either be a generic font family name, either ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, or ‘monospace’, or a list of font names in decreasing order of priority.
style:
The font style. This can be ‘normal’, ‘italic’ or ‘oblique’.
variant:
The font variant. This can be ‘normal’ or ‘small-caps’
stretch:
The stretching (spacing between letters) for the font. This can either be a numeric value in the range 0-1000 or one of ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’ or ‘ultra-expanded’.
weight:
The weight (or boldness) of the font. This can either be a numeric value in the range 0-1000 or one of ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’.
size:
The size of the font. This can either be a numeric value (e.g. 12), giving the size in points, or one of ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, or ‘xx-large’.

Default values are set by matplotlib or previously set values if set_font has already been called. Global default values can be set by editing the matplotlibrc file.

set_style(style)

Set the format of the x-axis tick labels. This can be ‘colons’ or ‘plain’:

  • ‘colons’ uses colons as separators, for example 31:41:59.26 +27:18:28.1
  • ‘plain’ uses letters and symbols as separators, for example 31h41m59.26s +27º18‘28.1”
set_xformat(format)

Set the format of the x-axis tick labels. If the x-axis type is longitude or latitude, then the options are:

  • ddd.ddddd - decimal degrees, where the number of decimal places can be varied
  • hh or dd - hours (or degrees)
  • hh:mm or dd:mm - hours and minutes (or degrees and arcminutes)
  • hh:mm:ss or dd:mm:ss - hours, minutes, and seconds (or degrees, arcminutes, and arcseconds)
  • hh:mm:ss.ss or dd:mm:ss.ss - hours, minutes, and seconds (or degrees, arcminutes, and arcseconds), where the number of decimal places can be varied.

If the x-axis type is scalar, then the format should be a valid python string format beginning with a %.

If one of these arguments is not specified, the format for that axis is left unchanged.

set_xposition(position)

Set the position of the x-axis tick labels (‘top’ or ‘bottom’)

set_yformat(format)

Set the format of the y-axis tick labels. If the y-axis type is longitude or latitude, then the options are:

  • ddd.ddddd - decimal degrees, where the number of decimal places can be varied
  • hh or dd - hours (or degrees)
  • hh:mm or dd:mm - hours and minutes (or degrees and arcminutes)
  • hh:mm:ss or dd:mm:ss - hours, minutes, and seconds (or degrees, arcminutes, and arcseconds)
  • hh:mm:ss.ss or dd:mm:ss.ss - hours, minutes, and seconds (or degrees, arcminutes, and arcseconds), where the number of decimal places can be varied.

If the y-axis type is scalar, then the format should be a valid python string format beginning with a %.

If one of these arguments is not specified, the format for that axis is left unchanged.

set_yposition(position)

Set the position of the y-axis tick labels (‘left’ or ‘right’)

show()

Show the x- and y-axis tick labels

show_x()

Show the x-axis tick labels

show_y()

Show the y-axis tick labels

Ticks

class aplpy.ticks.Ticks(parent)
hide()

Hide the x- and y-axis ticks

hide_x()

Hide the x-axis ticks

hide_y()

Hide the y-axis ticks

set_color(color)

Set the color of the ticks

set_length(length, minor_factor=0.5)

Set the length of the ticks (in points)

set_linewidth(linewidth)

Set the linewidth of the ticks (in points)

set_minor_frequency(frequency)

Set the number of subticks per major tick. Set to one to hide minor ticks.

set_xspacing(spacing)

Set the x-axis tick spacing, in degrees. To set the tick spacing to be automatically determined, set this to ‘auto’.

set_yspacing(spacing)

Set the y-axis tick spacing, in degrees. To set the tick spacing to be automatically determined, set this to ‘auto’.

show()

Show the x- and y-axis ticks

show_x()

Show the x-axis ticks

show_y()

Show the y-axis ticks

Advanced

FITSFigure.set_auto_refresh(refresh)

Set whether the display should refresh after each method call

Required Arguments:

refresh: [ True | False ]
Whether to refresh the display every time a FITSFigure method is called. The default is True. If set to false, the display can be refreshed manually using the refresh() method
FITSFigure.refresh(force=True)

Refresh the display

Optional Keyword Arguments:

force: [ True | False ]
If set to False, refresh() will only have an effect if auto refresh is on. If set to True, the display will be refreshed whatever the auto refresh setting is set to. The default is True.
FITSFigure.set_system_latex(usetex)

Set whether to use a real LaTeX installation or the built-in matplotlib LaTeX

Required Arguments:

usetex: [ True | False ]
Whether to use a real LaTex installation (True) or the built-in matplotlib LaTeX (False). Note that if the former is chosen, an installation of LaTex is required.

RGB Images

aplpy.make_rgb_cube(files, output, north=False, system=None, equinox=None)

Make an RGB data cube from a list of three FITS images.

This method can read in three FITS files with different projections/sizes/resolutions and uses Montage to reproject them all to the same projection.

Two files are produced by this function. The first is a three-dimensional FITS cube with a filename give by output, where the third dimension contains the different channels. The second is a two-dimensional FITS image with a filename given by output with a _2d suffix. This file contains the mean of the different channels, and is required as input to FITSFigure if show_rgb is subsequently used to show a color image generated from the FITS cube (to provide the correct WCS information to FITSFigure).

Required arguments:

files [ tuple | list ]
A list of the filenames of three FITS filename to reproject. The order is red, green, blue.
output [ string ]
The filename of the output RGB FITS cube.

Optional Keyword Arguments:

north [ True | False ]
By default, the FITS header generated by Montage represents the best fit to the images, often resulting in a slight rotation. If you want north to be straight up in your final mosaic, you should use this option.
system [ string ]
Specifies the system for the header (default is EQUJ). Possible values are: EQUJ EQUB ECLJ ECLB GAL SGAL
equinox [ string ]
If a coordinate system is specified, the equinox can also be given in the form YYYY. Default is J2000.
aplpy.make_rgb_image(data, output, indices=(0, 1, 2), vmin_r=None, vmax_r=None, pmin_r=0.25, pmax_r=99.75, stretch_r='linear', vmid_r=None, exponent_r=2, vmin_g=None, vmax_g=None, pmin_g=0.25, pmax_g=99.75, stretch_g='linear', vmid_g=None, exponent_g=2, vmin_b=None, vmax_b=None, pmin_b=0.25, pmax_b=99.75, stretch_b='linear', vmid_b=None, exponent_b=2, embed_avm_tags=False)

Make an RGB image from a FITS RGB cube or from three FITS files

Required arguments:

data: [ string | tuple | list ]
If a string, this is the filename of an RGB FITS cube. If a tuple or list, this should give the filename of three files to use for the red, green, and blue channel.
output: [ string ]
The output filename. The image type (e.g. PNG, JPEG, TIFF, ...) will be determined from the extension. Any image type supported by the Python Imaging Library can be used.

Optional keyword arguments:

indices: [ tuple ]
If data is the filename of a FITS cube, these indices are the positions in the third dimension to use for red, green, and blue respectively. The default is to use the first three indices.

vmin_r: [ None | float ]

vmin_g: [ None | float ]

vmin_b: [ None | float ]

Minimum pixel value to use for the red, green, and blue channels. If set to None for a given channel, the minimum pixel value for that channel is determined using the corresponding pmin_x argument (default).

vmax_r: [ None | float ]

vmax_g: [ None | float ]

vmax_b: [ None | float ]

Maximum pixel value to use for the red, green, and blue channels. If set to None for a given channel, the maximum pixel value for that channel is determined using the corresponding pmax_x argument (default).

pmin_r: [ float ]

pmin_g: [ float ]

pmin_b: [ float ]

Percentile values used to determine for a given channel the minimum pixel value to use for that channel if the corresponding vmin_x is set to None. The default is 0.25% for all channels.

pmax_r: [ float ]

pmax_g: [ float ]

pmax_b: [ float ]

Percentile values used to determine for a given channel the maximum pixel value to use for that channel if the corresponding vmax_x is set to None. The default is 99.75% for all channels.

stretch_r: [ ‘linear’ | ‘log’ | ‘sqrt’ | ‘arcsinh’ | ‘power’ ]

stretch_g: [ ‘linear’ | ‘log’ | ‘sqrt’ | ‘arcsinh’ | ‘power’ ]

stretch_b: [ ‘linear’ | ‘log’ | ‘sqrt’ | ‘arcsinh’ | ‘power’ ]

The stretch function to use for the different channels.

vmid_r: [ None | float ]

vmid_g: [ None | float ]

vmid_b: [ None | float ]

Baseline values used for the log and arcsinh stretches. If set to None, this is set to zero for log stretches and to vmin - (vmax - vmin) / 30. for arcsinh stretches

exponent_r: [ float ]

exponent_g: [ float ]

exponent_b: [ float ]

If stretch_x is set to ‘power’, this is the exponent to use.