WCSAxes#
- class astropy.visualization.wcsaxes.WCSAxes(fig, *args, wcs=None, transform=None, coord_meta=None, transData=None, slices=None, frame_class=None, **kwargs)[source]#
Bases:
AxesThe main axes class that can be used to show world coordinates from a WCS.
- Parameters:
- fig
Figure The figure to add the axes to.
- *args
*argscan be a single(left, bottom, width, height)rectangle or a singlematplotlib.transforms.Bbox. This specifies the rectangle (in figure coordinates) where the Axes is positioned.*argscan also consist of three numbers or a single three-digit number; in the latter case, the digits are considered as independent numbers. The numbers are interpreted as(nrows, ncols, index):(nrows, ncols)specifies the size of an array of subplots, andindexis the 1-based index of the subplot being created. Finally,*argscan also directly be amatplotlib.gridspec.SubplotSpecinstance.- wcs
WCS, optional The WCS for the data. If this is specified,
transformcannot be specified.- transform
Transform, optional The transform for the data. If this is specified,
wcscannot be specified.- coord_meta
dict, optional A dictionary providing additional metadata when
transformis specified. This should include the keystype,wrap, andunit. Each of these should be a list with as many items as the dimension of the WCS. Thetypeentries should be one oflongitude,latitude, orscalar, thewrapentries should give, for the longitude, the angle at which the coordinate wraps (andNoneotherwise), and theunitshould give the unit of the coordinates asUnitinstances. This can optionally also include aformat_unitentry giving the units to use for the tick labels (if not specified, this defaults tounit).- transData
Transform, optional Can be used to override the default data -> pixel mapping.
- slices
tuple, optional For WCS transformations with more than two dimensions, we need to choose which dimensions are being shown in the 2D image. The slice should contain one
xentry, oneyentry, and the rest of the values should be integers indicating the slice through the data. The order of the items in the slice should be the same as the order of the dimensions in theWCS, and the opposite of the order of the dimensions in Numpy. For example,(50, 'x', 'y')means that the first WCS dimension (last Numpy dimension) will be sliced at an index of 50, the second WCS and Numpy dimension will be shown on the x axis, and the final WCS dimension (first Numpy dimension) will be shown on the y-axis (and therefore the data will be plotted usingdata[:, :, 50].transpose()).- frame_classtype, optional
The class for the frame, which should be a subclass of
BaseFrame. The default is to use aRectangularFrame.- **kwargs
Additional keyword arguments are passed to
Axes.
- fig
- Attributes:
- coords
CoordinatesMap Container for coordinate information.
- coords
Methods Summary
contour(*args, **kwargs)Plot contours.
contourf(*args, **kwargs)Plot filled contours.
draw(renderer)Draw the axes.
draw_wcsaxes(renderer)get_coords_overlay(frame[, coord_meta])Get coordinates overlay on given frame.
get_tightbbox(renderer, *args, **kwargs)Return the tight bounding box of the Axes, including axis and their decorators (xlabel, title, etc).
get_transform(frame)Return a transform from the specified frame to display coordinates.
Get the xlabel text string.
Get the ylabel text string.
grid([b, axis, which])Plot gridlines for both coordinates.
imshow(X, *args, **kwargs)Wrapper to Matplotlib's
imshow().plot_coord(*args, **kwargs)Plot
SkyCoordorBaseCoordinateFrameobjects onto the axes.reset_wcs([wcs, slices, transform, coord_meta])Reset the current Axes, to use a new WCS object.
scatter_coord(*args, **kwargs)Scatter
SkyCoordorBaseCoordinateFrameobjects onto the axes.set(*[, adjustable, agg_filter, alpha, ...])Set multiple properties at once.
set_xlabel([xlabel, labelpad, loc])Set x-label.
set_ylabel([ylabel, labelpad, loc])Set y-label.
text_coord(*args, **kwargs)Print a text string using
SkyCoordorBaseCoordinateFrameobjects onto the axes.tick_params([axis])Method to set the tick and tick label parameters in the same way as the
tick_params()method in Matplotlib.Methods Documentation
- contour(*args, **kwargs)[source]#
Plot contours.
This is a custom implementation of
contour()which applies the transform (if specified) to all contours in one go for performance rather than to each contour line individually.- Parameters:
- *args, **kwargs
All positional and keyword arguments are the same as for
contour().
- contourf(*args, **kwargs)[source]#
Plot filled contours.
This is a custom implementation of
contourf()which applies the transform (if specified) to all contours in one go for performance rather than to each contour line individually.- Parameters:
- *args, **kwargs
All positional and keyword arguments are the same as for
contourf().
- draw(renderer)[source]#
Draw the axes.
- Parameters:
- renderer
RendererBase The renderer to draw with.
- renderer
- get_coords_overlay(frame, coord_meta=None)[source]#
Get coordinates overlay on given frame.
- Parameters:
- frame
str,BaseCoordinateFrame Frame to get overlay for. If a string must correspond to one of the coordinate frames registered in the astropy frame transform graph.
- coord_meta
dict Metadata for the coordinates overlay.
- frame
- Returns:
- overlay
CoordinatesMap Coordinates overlay.
- overlay
- get_tightbbox(renderer, *args, **kwargs)[source]#
Return the tight bounding box of the Axes, including axis and their decorators (xlabel, title, etc).
Artists that have
artist.set_in_layout(False)are not included in the bbox.- Parameters:
- renderer
RendererBasesubclass renderer that will be used to draw the figures (i.e.
fig.canvas.get_renderer())- bbox_extra_artists
listofArtistorNone List of artists to include in the tight bounding box. If
None(default), then all artist children of the Axes are included in the tight bounding box.- call_axes_locatorbool, default:
True If call_axes_locator is
False, it does not call the_axes_locatorattribute, which is necessary to get the correct bounding box.call_axes_locator=Falsecan be used if the caller is only interested in the relative size of the tightbbox compared to the Axes bbox.- for_layout_onlydefault:
False The bounding box will not include the x-extent of the title and the xlabel, or the y-extent of the ylabel.
- renderer
- Returns:
BboxBaseBounding box in figure pixel coordinates.
- get_transform(frame)[source]#
Return a transform from the specified frame to display coordinates.
This includes the transData transformation
- Parameters:
- frame
WCSorTransformorstr - The
frameparameter can have several possible types: WCSinstance: assumed to be a transformation from pixel to world coordinates, where the world coordinates are the same as those in the WCS transformation used for thisWCSAxesinstance. This is used for example to show contours, since this involves plotting an array in pixel coordinates that are not the final data coordinate and have to be transformed to the common world coordinate system first.Transforminstance: it is assumed to be a transform to the world coordinates that are part of the WCS used to instantiate thisWCSAxesinstance.'pixel'or'world': return a transformation that allows users to plot in pixel/data coordinates (essentially an identity transform) andworld(the default world-to-pixel transformation used to instantiate theWCSAxesinstance).'fk5'or'galactic': return a transformation from the specified frame to the pixel/data coordinates. In this case, the values are assumed to be in degrees.BaseCoordinateFrameinstance. In this case, the values are assumed to be in degrees.
- The
- frame
- grid(b=None, axis='both', *, which='major', **kwargs)[source]#
Plot gridlines for both coordinates.
Standard matplotlib appearance options (color, alpha, etc.) can be passed as keyword arguments. This behaves like
matplotlib.axes.Axesexcept that if no arguments are specified, the grid is shown rather than toggled.
- imshow(X, *args, **kwargs)[source]#
Wrapper to Matplotlib’s
imshow().If an RGB image is passed as a PIL object, it will be flipped vertically and
originwill be set tolower, since WCS transformations - like FITS files - assume that the origin is the lower left pixel of the image (whereas RGB images have the origin in the top left).- Parameters:
- Xarray_like
The image data, as for
imshow(). A PIL image is also accepted.- *args, **kwargs
All other arguments are passed to
imshow().
- plot_coord(*args, **kwargs)[source]#
Plot
SkyCoordorBaseCoordinateFrameobjects onto the axes.The first argument to
plot_coord()should be a coordinate, which will then be converted to the first two parameters tomatplotlib.axes.Axes.plot. All other arguments are the same asmatplotlib.axes.Axes.plot. If not specified atransformkeyword argument will be created based on the coordinate.- Parameters:
- *args
The first positional argument should be the coordinate object to plot on the axes, as a
SkyCoordorBaseCoordinateFrameinstance. This is converted to the first two arguments tomatplotlib.axes.Axes.plot, and any remaining positional arguments are passed on unchanged.- **kwargs
All keyword arguments are passed to
matplotlib.axes.Axes.plot.
See also
matplotlib.axes.Axes.plotThis method is called from this function with all arguments passed to it.
- reset_wcs(wcs=None, slices=None, transform=None, coord_meta=None)[source]#
Reset the current Axes, to use a new WCS object.
- Parameters:
- wcs
WCS, optional The new WCS for the data. See the
WCSAxesdocumentation for a full description of this and the following arguments.- slices
tuple, optional For WCS transformations with more than two dimensions, the dimensions being shown in the 2D image.
- transform
Transform, optional The transform for the data, as an alternative to
wcs.- coord_meta
dict, optional A dictionary providing additional metadata when
transformis specified. See theWCSAxesdocumentation for a full description of the accepted keys.
- wcs
- scatter_coord(*args, **kwargs)[source]#
Scatter
SkyCoordorBaseCoordinateFrameobjects onto the axes.The first argument to
scatter_coord()should be a coordinate, which will then be converted to the first two parameters tomatplotlib.axes.Axes.scatter. All other arguments are the same asmatplotlib.axes.Axes.scatter. If not specified atransformkeyword argument will be created based on the coordinate.- Parameters:
- *args
The first positional argument should be the coordinate object to scatter on the axes, as a
SkyCoordorBaseCoordinateFrameinstance. This is converted to the first two arguments tomatplotlib.axes.Axes.scatter, and any remaining positional arguments are passed on unchanged.- **kwargs
All keyword arguments are passed to
matplotlib.axes.Axes.scatter.
See also
matplotlib.axes.Axes.scatterThis method is called from this function with all arguments passed to it.
- set(*, adjustable=<UNSET>, agg_filter=<UNSET>, alpha=<UNSET>, anchor=<UNSET>, animated=<UNSET>, aspect=<UNSET>, autoscale_on=<UNSET>, autoscalex_on=<UNSET>, autoscaley_on=<UNSET>, axes_locator=<UNSET>, axisbelow=<UNSET>, box_aspect=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, facecolor=<UNSET>, forward_navigation_events=<UNSET>, frame_on=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, navigate=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, prop_cycle=<UNSET>, rasterization_zorder=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, subplotspec=<UNSET>, title=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, xbound=<UNSET>, xinverted=<UNSET>, xlabel=<UNSET>, xlim=<UNSET>, xmargin=<UNSET>, xscale=<UNSET>, xticklabels=<UNSET>, xticks=<UNSET>, ybound=<UNSET>, yinverted=<UNSET>, ylabel=<UNSET>, ylim=<UNSET>, ymargin=<UNSET>, yscale=<UNSET>, yticklabels=<UNSET>, yticks=<UNSET>, zorder=<UNSET>)#
Set multiple properties at once.
a.set(a=A, b=B, c=C)
is equivalent to
a.set_a(A) a.set_b(B) a.set_c(C)
In addition to the full property names, aliases are also supported, e.g.
set(lw=2)is equivalent toset(linewidth=2), but it is an error to pass both simultaneously.The order of the individual setter calls matches the order of parameters in
set(). However, most properties do not depend on each other so that order is rarely relevant.Supported properties are
- Properties:
adjustable: {‘box’, ‘datalim’} agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: float or None anchor: (float, float) or {‘C’, ‘SW’, ‘S’, ‘SE’, ‘E’, ‘NE’, …} animated: bool aspect: {‘auto’, ‘equal’} or float autoscale_on: bool autoscalex_on: unknown autoscaley_on: unknown axes_locator: Callable[[Axes, Renderer], Bbox] axisbelow: bool or ‘line’ box_aspect: float or None clip_box:
BboxBaseor None clip_on: bool clip_path: Patch or (Path, Transform) or None facecolor or fc: color figure:FigureorSubFigureforward_navigation_events: bool or “auto” frame_on: bool gid: str in_layout: bool label: object mouseover: bool navigate: bool navigate_mode: unknown path_effects: list ofAbstractPathEffectpicker: None or bool or float or callable position: [left, bottom, width, height] orBboxprop_cycle:Cyclerrasterization_zorder: float or None rasterized: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None subplotspec: unknown title: str transform:Transformurl: str visible: bool xbound: (lower: float, upper: float) xinverted: unknown xlabel: str xlim: (left: float, right: float) xmargin: float greater than -0.5 xscale: unknown xticklabels: unknown xticks: unknown ybound: (lower: float, upper: float) yinverted: unknown ylabel: str ylim: (bottom: float, top: float) ymargin: float greater than -0.5 yscale: unknown yticklabels: unknown yticks: unknown zorder: float
- set_xlabel(xlabel=None, labelpad=1, loc=None, **kwargs)[source]#
Set x-label.
- Parameters:
- xlabel
str The label text.
- labelpad
float, optional The minimum distance between the label and the axis, in points.
- loc
str, optional Not supported by WCSAxes and ignored.
- **kwargs
Additional keyword arguments are passed to
set_axislabel.
- xlabel
- set_ylabel(ylabel=None, labelpad=1, loc=None, **kwargs)[source]#
Set y-label.
- Parameters:
- ylabel
str The label text.
- labelpad
float, optional The minimum distance between the label and the axis, in points.
- loc
str, optional Not supported by WCSAxes and ignored.
- **kwargs
Additional keyword arguments are passed to
set_axislabel.
- ylabel
- text_coord(*args, **kwargs)[source]#
Print a text string using
SkyCoordorBaseCoordinateFrameobjects onto the axes.The first argument to
text_coord()should be a coordinate, which will then be converted to the first two parameters tomatplotlib.axes.Axes.text. All other arguments are the same asmatplotlib.axes.Axes.text. If not specified atransformkeyword argument will be created based on the coordinate.- Parameters:
- *args
The first positional argument should be the coordinate object to plot on the axes, as a
SkyCoordorBaseCoordinateFrameinstance. This is converted to the first two arguments tomatplotlib.axes.Axes.text, and any remaining positional arguments are passed on unchanged.- **kwargs
All keyword arguments are passed to
matplotlib.axes.Axes.text.
See also
matplotlib.axes.Axes.textThis method is called from this function with all arguments passed to it.
- tick_params(axis='both', **kwargs)[source]#
Method to set the tick and tick label parameters in the same way as the
tick_params()method in Matplotlib.This is provided for convenience, but the recommended API is to use
set_ticks(),set_ticklabel(),set_ticks_position(),set_ticklabel_position(), andgrid().- Parameters:
- axis
intorstr, optional Which axis to apply the parameters to. This defaults to ‘both’ but this can also be set to an
intorstrthat refers to the axis to apply it to, following the valid values that can indexax.coords. Note that'x'and'y’ are also accepted in the case of rectangular axes.- which{‘both’, ‘major’, ‘minor’}, optional
Which ticks to apply the settings to. By default, setting are applied to both major and minor ticks. Note that if
'minor'is specified, only the length of the ticks can be set currently.- direction{‘in’, ‘out’}, optional
Puts ticks inside the axes, or outside the axes.
- length
float, optional Tick length in points.
- width
float, optional Tick width in points.
- colorcolor, optional
Tick color (accepts any valid Matplotlib color)
- pad
float, optional Distance in points between tick and label.
- labelsize
floatorstr, optional Tick label font size in points or as a string (e.g., ‘large’).
- labelcolorcolor, optional
Tick label color (accepts any valid Matplotlib color)
- colorscolor, optional
- Changes the tick color and the label color to the same value
(accepts any valid Matplotlib color).
- bottom, top, left, rightbool, optional
Where to draw the ticks. Note that this can only be given if a specific coordinate is specified via the
axisargument, and it will not work correctly if the frame is not rectangular.- labelbottom, labeltop, labelleft, labelrightbool, optional
Where to draw the tick labels. Note that this can only be given if a specific coordinate is specified via the
axisargument, and it will not work correctly if the frame is not rectangular.- grid_colorcolor, optional
The color of the grid lines (accepts any valid Matplotlib color).
- grid_alpha
float, optional Transparency of grid lines: 0 (transparent) to 1 (opaque).
- grid_linewidth
float, optional Width of grid lines in points.
- grid_linestyle
str, optional The style of the grid lines (accepts any valid Matplotlib line style).
- axis