WCSAxes¶
-
class
astropy.visualization.wcsaxes.
WCSAxes
(fig, rect, wcs=None, transform=None, coord_meta=None, transData=None, slices=None, frame_class=<class 'astropy.visualization.wcsaxes.frame.RectangularFrame'>, **kwargs)[source] [edit on github]¶ Bases:
matplotlib.axes.Axes
The main axes class that can be used to show world coordinates from a WCS.
Parameters: - fig :
Figure
The figure to add the axes to
- rect : list
The position of the axes in the figure in relative units. Should be given as
[left, bottom, width, height]
.- wcs :
WCS
, optional The WCS for the data. If this is specified,
transform
cannot be specified.- transform :
Transform
, optional The transform for the data. If this is specified,
wcs
cannot be specified.- coord_meta : dict, optional
A dictionary providing additional metadata when
transform
is 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. Thetype
entries should be one oflongitude
,latitude
, orscalar
, thewrap
entries should give, for the longitude, the angle at which the coordinate wraps (andNone
otherwise), and theunit
should give the unit of the coordinates asUnit
instances. This can optionally also include aformat_unit
entry 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
x
entry, oney
entry, 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_class : type, optional
The class for the frame, which should be a subclass of
BaseFrame
. The default is to use aRectangularFrame
Methods Summary
contour
(*args, **kwargs)Plot contours. contourf
(*args, **kwargs)Plot filled contours. draw
(renderer[, inframe])Draw everything (plot lines, axes, labels) draw_wcsaxes
(renderer)get_coords_overlay
(frame[, coord_meta])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_xlabel
()Get the xlabel text string. get_ylabel
()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 SkyCoord
orBaseCoordinateFrame
objects onto the axes.reset_wcs
([wcs, slices, transform, coord_meta])Reset the current Axes, to use a new WCS object. set_xlabel
([xlabel, labelpad])Set the label for the x-axis. set_ylabel
([ylabel, labelpad])Set the label for the y-axis. 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] [edit on github]¶ 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. All positional and keyword arguments are the same as forcontour()
.
-
contourf
(*args, **kwargs)[source] [edit on github]¶ 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. All positional and keyword arguments are the same as forcontourf()
.
-
draw
(renderer, inframe=False)[source] [edit on github]¶ Draw everything (plot lines, axes, labels)
-
draw_wcsaxes
(renderer)[source] [edit on github]¶
-
get_coords_overlay
(frame, coord_meta=None)[source] [edit on github]¶
-
get_tightbbox
(renderer, *args, **kwargs)[source] [edit on github]¶ 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 :
RendererBase
instance renderer that will be used to draw the figures (i.e.
fig.canvas.get_renderer()
)- bbox_extra_artists : list of
Artist
orNone
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_locator : boolean (default
True
) If call_axes_locator is
False
, it does not call the_axes_locator
attribute, which is necessary to get the correct bounding box.call_axes_locator=False
can be used if the caller is only interested in the relative size of the tightbbox compared to the axes bbox.
Returns: - bbox :
BboxBase
bounding box in figure pixel coordinates.
- renderer :
-
get_transform
(frame)[source] [edit on github]¶ Return a transform from the specified frame to display coordinates.
This does not include the transData transformation
Parameters: - frame :
WCS
orTransform
or str - The
frame
parameter can have several possible types: WCS
instance: 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 thisWCSAxes
instance. 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.Transform
instance: it is assumed to be a transform to the world coordinates that are part of the WCS used to instantiate thisWCSAxes
instance.'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 theWCSAxes
instance).'fk5'
or'galactic'
: return a transformation from the specified frame to the pixel/data coordinates.BaseCoordinateFrame
instance.
- The
- frame :
-
get_xlabel
()[source] [edit on github]¶ Get the xlabel text string.
-
get_ylabel
()[source] [edit on github]¶ Get the ylabel text string.
-
grid
(b=None, axis='both', *, which='major', **kwargs)[source] [edit on github]¶ Plot gridlines for both coordinates.
Standard matplotlib appearance options (color, alpha, etc.) can be passed as keyword arguments. This behaves like
matplotlib.axes.Axes
except that if no arguments are specified, the grid is shown rather than toggled.Parameters: - b : bool
Whether to show the gridlines.
-
imshow
(X, *args, **kwargs)[source] [edit on github]¶ Wrapper to Matplotlib’s
imshow()
.If an RGB image is passed as a PIL object, it will be flipped vertically and
origin
will 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).All arguments are passed to
imshow()
.
-
plot_coord
(*args, **kwargs)[source] [edit on github]¶ Plot
SkyCoord
orBaseCoordinateFrame
objects 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 atransform
keyword argument will be created based on the coordinate.Parameters: - coordinate :
SkyCoord
orBaseCoordinateFrame
The coordinate object to plot on the axes. This is converted to the first two arguments to
matplotlib.axes.Axes.plot
.
See also
matplotlib.axes.Axes.plot
- This method is called from this function with all arguments passed to it.
- coordinate :
-
reset_wcs
(wcs=None, slices=None, transform=None, coord_meta=None)[source] [edit on github]¶ Reset the current Axes, to use a new WCS object.
-
set_xlabel
(xlabel=None, labelpad=1, **kwargs)[source] [edit on github]¶ Set the label for the x-axis.
Parameters: - xlabel : str
The label text.
- labelpad : scalar, optional, default: None
Spacing in points between the label and the x-axis.
Other Parameters: - **kwargs :
Text
properties Text
properties control the appearance of the label.
See also
text
- for information on how override and the optional args work
-
set_ylabel
(ylabel=None, labelpad=1, **kwargs)[source] [edit on github]¶ Set the label for the y-axis.
Parameters: - ylabel : str
The label text.
- labelpad : scalar, optional, default: None
Spacing in points between the label and the y-axis.
Other Parameters: - **kwargs :
Text
properties Text
properties control the appearance of the label.
See also
text
- for information on how override and the optional args work
-
tick_params
(axis='both', **kwargs)[source] [edit on github]¶ 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 : int or str, optional
Which axis to apply the parameters to. This defaults to ‘both’ but this can also be set to an
int
orstr
that 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.
- color : color, optional
Tick color (accepts any valid Matplotlib color)
- pad : float, optional
Distance in points between tick and label.
- labelsize : float or str, optional
Tick label font size in points or as a string (e.g., ‘large’).
- labelcolor : color, optional
Tick label color (accepts any valid Matplotlib color)
- colors : color, optional
- Changes the tick color and the label color to the same value
(accepts any valid Matplotlib color).
- bottom, top, left, right : bool, optional
Where to draw the ticks. Note that this can only be given if a specific coordinate is specified via the
axis
argument, and it will not work correctly if the frame is not rectangular.- labelbottom, labeltop, labelleft, labelright : bool, optional
Where to draw the tick labels. Note that this can only be given if a specific coordinate is specified via the
axis
argument, and it will not work correctly if the frame is not rectangular.- grid_color : color, 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 : string, optional
The style of the grid lines (accepts any valid Matplotlib line style).
- fig :