TextPixelRegion

class regions.TextPixelRegion(center, text, meta=None, visual=None)[source]

Bases: PointPixelRegion

A text string in pixel coordinates.

Parameters:
centerPixCoord

The leftmost point of the text string before rotation.

textstr

The text string.

metaRegionMeta or dict, optional

A dictionary that stores the meta attributes of the region.

visualRegionVisual or dict, optional

A dictionary that stores the visual meta attributes of the region.

Examples

from regions import PixCoord, TextPixelRegion, RegionVisual
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1)

center = PixCoord(x=15, y=10)
visual = RegionVisual({'textangle': 30})
reg = TextPixelRegion(center=center, text="Hello World!",
                      visual=visual)
reg.plot(ax=ax)

ax.set_xlim(10, 30)
ax.set_ylim(2.5, 20)
ax.set_aspect('equal')

(Source code, png, hires.png, pdf, svg)

../_images/regions-TextPixelRegion-1.png

Attributes Summary

center

The leftmost pixel position (before rotation) as a PixCoord.

meta

The meta attributes as a RegionMeta

visual

The visual attributes as a RegionVisual.

Methods Summary

as_artist([origin])

Return a matplotlib Text object for this region (matplotlib.text.Text).

to_sky(wcs)

Return a region defined in sky coordinates.

to_spherical_sky([wcs, ...])

Convert to an equivalent spherical SphericalSkyRegion instance.

Attributes Documentation

center

The leftmost pixel position (before rotation) as a PixCoord.

meta

The meta attributes as a RegionMeta

visual

The visual attributes as a RegionVisual.

Methods Documentation

as_artist(origin=(0, 0), **kwargs)[source]

Return a matplotlib Text object for this region (matplotlib.text.Text).

Parameters:
originarray_like, optional

The (x, y) pixel position of the origin of the displayed image.

**kwargsdict

Any keyword arguments accepted by Text. These keywords will override any visual meta attributes of this region.

Returns:
artistText

A matplotlib Text object.

to_sky(wcs)[source]

Return a region defined in sky coordinates.

Parameters:
wcsWCS

The world coordinate system transformation to use to convert from pixels to sky coordinates.

Returns:
sky_regionSkyRegion

The sky region.

to_spherical_sky(wcs=None, include_boundary_distortions=False, discretize_kwargs=None)[source]

Convert to an equivalent spherical SphericalSkyRegion instance.

Parameters:
wcsWCS instance, optional

The world coordinate system transformation to use to convert between sky and pixel coordinates. Required if transforming with boundary distortions (if include_boundary_distortions is True). Ignored if boundary distortions not included.

include_boundary_distortionsbool, optional

If True, accounts for boundary boundary distortions in spherical to planar conversions, by discretizing the boundary and converting the boundary polygon. Default is False, which converts to an equivalent idealized shape.

discretize_kwargsdict, optional

Optional keyword arguments to pass to discretize_boundary() method if including boundary distortions.

Returns:
spherical_sky_regionSphericalSkyRegion

A spherical sky region, with an equivalent shape (if include_boundary_distortions is False), or a discretized polygon of the boundary (if include_boundary_distortions is True).