Data Visualization (astropy.visualization)

Introduction

astropy.visualization provides functionality that can be helpful when visualizing data. This includes a framework for plotting Astronomical images with coordinates with Matplotlib (previously the standalone wcsaxes package), functionality related to image normaliation (including both scaling and stretching), smart histogram plotting, RGB color image creation from separate images, and custom plotting styles for Matplotlib.

Astropy matplotlib style

The visualization package contains two dictionaries that can be used to set the Matplotlib plotting style:

astropy_mpl_style

Improves some settings over the matplotlib default style.

astropy_mpl_docs_style

Matplotlib style used by the Astropy documentation.

To apply the custom style on top of your existing matplotlib style, perform the following:

Using matplotlib version >= 1.5:

>>> import matplotlib.pyplot as plt
>>> from astropy.visualization import astropy_mpl_style
>>> plt.style.use(astropy_mpl_style)

For older versions of matplotlib:

>>> import matplotlib as mpl
>>> from astropy.visualization import astropy_mpl_style
>>> mpl.rcParams.update(astropy_mpl_style)

Note that these styles are applied on top your existing matplotlib style. If you want an exactly reproducible plot (i.e. if you want the plot to come out exactly the same independent of the user configuration), you should reset the matplotlib settings to the defaults before applying the astropy style.

Using matplotlib version >= 1.5:

>>> import matplotlib.pyplot as plt
>>> from astropy.visualization import astropy_mpl_style
>>> plt.style.use('default')
>>> plt.style.use(astropy_mpl_style)

For older versions of matplotlib:

>>> import matplotlib as mpl
>>> from astropy.visualization import astropy_mpl_style
>>> mpl.rcdefaults()
>>> mpl.rcParams.update(astropy_mpl_style)

Scripts

This module includes a command-line script, fits2bitmap to convert FITS images to bitmaps, including scaling and stretching of the image. To find out more about the available options and how to use it, type:

$ fits2bitmap --help

Reference/API

astropy.visualization.mpl_style Module

This module contains dictionaries that can be used to set a matplotlib plotting style. It is mostly here to allow a consistent plotting style in tutorials, but can be used to prepare any matplotlib figure.

astropy.visualization Package

Functions

hist(x[, bins, ax]) Enhanced histogram function
make_lupton_rgb(image_r, image_g, image_b[, …]) Return a Red/Green/Blue color image from up to 3 images using an asinh stretch.
quantity_support([format]) Enable support for plotting astropy.units.Quantity instances in matplotlib.
simple_norm(data[, stretch, power, asinh_a, …]) Return a Normalization class that can be used for displaying images with Matplotlib.

Classes

AsinhStretch([a]) An asinh stretch.
AsymmetricPercentileInterval(…[, n_samples]) Interval based on a keeping a specified fraction of pixels (can be asymmetric).
BaseInterval Base class for the interval classes, which, when called with an array of values, return an interval computed following different algorithms.
BaseStretch Base class for the stretch classes, which, when called with an array of values in the range [0:1], return an transformed array of values, also in the range [0:1].
BaseTransform A transformation object.
CompositeTransform(transform_1, transform_2) A combination of two transforms.
ContrastBiasStretch(contrast, bias) A stretch that takes into account contrast and bias.
HistEqStretch(data[, values]) A histogram equalization stretch.
ImageNormalize([data, interval, vmin, vmax, …]) Normalization class to be used with Matplotlib.
LinearStretch A linear stretch.
LogStretch([a]) A log stretch.
ManualInterval([vmin, vmax]) Interval based on user-specified values.
MinMaxInterval Interval based on the minimum and maximum values in the data.
PercentileInterval(percentile[, n_samples]) Interval based on a keeping a specified fraction of pixels.
PowerDistStretch([a]) An alternative power stretch.
PowerStretch(a) A power stretch.
SinhStretch([a]) A sinh stretch.
SqrtStretch A square root stretch.
SquaredStretch() A convenience class for a power stretch of 2.
ZScaleInterval([nsamples, contrast, …]) Interval based on IRAF’s zscale.

Class Inheritance Diagram

Inheritance diagram of astropy.visualization.stretch.AsinhStretch, astropy.visualization.interval.AsymmetricPercentileInterval, astropy.visualization.interval.BaseInterval, astropy.visualization.stretch.BaseStretch, astropy.visualization.transform.BaseTransform, astropy.visualization.transform.CompositeTransform, astropy.visualization.stretch.ContrastBiasStretch, astropy.visualization.stretch.HistEqStretch, astropy.visualization.mpl_normalize.ImageNormalize, astropy.visualization.stretch.LinearStretch, astropy.visualization.stretch.LogStretch, astropy.visualization.interval.ManualInterval, astropy.visualization.interval.MinMaxInterval, astropy.visualization.interval.PercentileInterval, astropy.visualization.stretch.PowerDistStretch, astropy.visualization.stretch.PowerStretch, astropy.visualization.stretch.SinhStretch, astropy.visualization.stretch.SqrtStretch, astropy.visualization.stretch.SquaredStretch, astropy.visualization.interval.ZScaleInterval

astropy.visualization.mpl_normalize Module

Normalization class for Matplotlib that can be used to produce colorbars.

Functions

simple_norm(data[, stretch, power, asinh_a, …]) Return a Normalization class that can be used for displaying images with Matplotlib.

Classes

ImageNormalize([data, interval, vmin, vmax, …]) Normalization class to be used with Matplotlib.

Class Inheritance Diagram

Inheritance diagram of astropy.visualization.mpl_normalize.ImageNormalize