Plot#

class gwpy.plot.Plot(*data: ArrayLike | IterableType, **kwargs)[source]#

Bases: Figure

An extension of the core matplotlib Figure.

The Plot provides a number of methods to simplify generating figures from GWpy data objects, and modifying them on-the-fly in interactive mode.

Methods Summary

add_segments_bar(segments[, ax, height, ...])

Add a segment bar Plot indicating state information.

close()

Close the plot and release its memory.

colorbar([mappable, cax, ax, fraction, emit])

Add a colorbar to the current Plot.

get_axes([projection])

Find all Axes, optionally matching the given projection.

refresh()

Refresh the current figure.

save(fname, **kwargs)

Save the figure to disk.

set(*[, agg_filter, alpha, animated, ...])

Set multiple properties at once.

show([warn, block])

Display the current figure (if possible).

Methods Documentation

add_segments_bar(
segments: DataQualityFlag,
ax: Axes | None = None,
height: float = 0.14,
pad: float = 0.1,
*,
sharex: bool = True,
location: Literal['top', 'bottom'] = 'bottom',
**plotargs,
) SegmentAxes[source]#

Add a segment bar Plot indicating state information.

By default, segments are displayed in a thin horizontal set of Axes sitting immediately below the x-axis of the main, similarly to a colorbar.

Parameters:
segmentsDataQualityFlag

A data-quality flag, or SegmentList denoting state segments about this Plot.

axAxes, optional

Specific Axes relative to which to position new Axes, defaults to gca().

heightfloat, optional

Height of the new axes, as a fraction of the anchor axes.

padfloat, optional

Padding between the new axes and the anchor, as a fraction of the anchor axes dimension.

sharexTrue, Axes, optional

Either True to set sharex=ax for the new segment axes, or an Axes to use directly.

locationstr, optional

Location for new segment axes, defaults to 'bottom', acceptable values are 'top' or 'bottom'.

plotargs

Other keyword arguments are passed to plot().

See also

SegmentAxes

For more details about segment axes.

close() None[source]#

Close the plot and release its memory.

colorbar(
mappable: Collection | AxesImage | None = None,
*,
cax: Axes | None = None,
ax: Axes | None = None,
fraction: float = 0.0,
emit: bool = True,
**kwargs,
) Colorbar[source]#

Add a colorbar to the current Plot.

This method differs from the default matplotlib.figure.Figure.colorbar() in that it doesn’t resize the parent Axes to accommodate the colorbar, but rather draws a new Axes alongside it.

Parameters:
mappableAxesImage, Collection, optional

Collection against which to map the colorbar. Default is the most-recently-added mappable artist.

caxAxes, optional

Axes on which to draw colorbar. By default a new Axes will be created.

axAxes

Axes relative to which to position colorbar. The default is the Axes containing the mappable.

fractionfloat, optional

Fraction of original axes to use for colorbar. The default (fraction=0) is to not resize the original axes at all.

emitbool, optional

If True update all mappables on Axes to match the same colouring as the colorbar.

kwargs

Other keyword arguments are passed to colorbar().

Returns:
cbarColorbar

The newly added Colorbar.

Notes

To revert to the default matplotlib behaviour, pass fraction=0.15.

Examples

>>> import numpy
>>> from gwpy.plot import Plot

To plot a simple image and add a colorbar:

>>> plot = Plot()
>>> ax = plot.gca()
>>> ax.imshow(numpy.random.randn(120).reshape((10, 12)))
>>> plot.colorbar(label='Value')
>>> plot.show()

Colorbars can also be generated by directly referencing the parent axes:

>>> Plot = Plot()
>>> ax = plot.gca()
>>> ax.imshow(numpy.random.randn(120).reshape((10, 12)))
>>> ax.colorbar(label='Value')
>>> plot.show()
../../_images/gwpy-plot-Plot-1_00.png

(png)#

../../_images/gwpy-plot-Plot-1_01.png

(png)#

get_axes(projection: str | None = None) list[Axes][source]#

Find all Axes, optionally matching the given projection.

Parameters:
projectionstr

Name of axes types to return.

Returns:
axlistlist of Axes

The Axes that match the given projection.

refresh() None[source]#

Refresh the current figure.

save(fname: str | Path | BinaryIO, **kwargs) None[source]#

Save the figure to disk.

This method is an alias to savefig(), all arguments are passed directory to that method.

set(
*,
agg_filter=<UNSET>,
alpha=<UNSET>,
animated=<UNSET>,
canvas=<UNSET>,
clip_box=<UNSET>,
clip_on=<UNSET>,
clip_path=<UNSET>,
constrained_layout=<UNSET>,
constrained_layout_pads=<UNSET>,
dpi=<UNSET>,
edgecolor=<UNSET>,
facecolor=<UNSET>,
figheight=<UNSET>,
figwidth=<UNSET>,
frameon=<UNSET>,
gid=<UNSET>,
in_layout=<UNSET>,
label=<UNSET>,
layout_engine=<UNSET>,
linewidth=<UNSET>,
mouseover=<UNSET>,
path_effects=<UNSET>,
picker=<UNSET>,
rasterized=<UNSET>,
size_inches=<UNSET>,
sketch_params=<UNSET>,
snap=<UNSET>,
tight_layout=<UNSET>,
transform=<UNSET>,
url=<UNSET>,
visible=<UNSET>,
zorder=<UNSET>,
)#

Set multiple properties at once.

Supported properties are

Properties:

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 animated: bool canvas: FigureCanvas clip_box: BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None constrained_layout: unknown constrained_layout_pads: unknown dpi: float edgecolor: color facecolor: color figheight: float figure: unknown figwidth: float frameon: bool gid: str in_layout: bool label: object layout_engine: {‘constrained’, ‘compressed’, ‘tight’, ‘none’, LayoutEngine, None} linewidth: number mouseover: bool path_effects: list of AbstractPathEffect picker: None or bool or float or callable rasterized: bool size_inches: (float, float) or float sketch_params: (scale: float, length: float, randomness: float) snap: bool or None tight_layout: unknown transform: Transform url: str visible: bool zorder: float

show(warn: bool = True, block: bool | None = None) None[source]#

Display the current figure (if possible).

If blocking, this method replicates the behaviour of matplotlib.pyplot.show(), otherwise it just calls up to show().

This method also supports repeatedly showing the same figure, even after closing the display window, which isn’t supported by pyplot.show (AFAIK).

Parameters:
blockbool, optional

open the figure and block until the figure is closed, otherwise open the figure as a detached window, default: None. If None, block if using an interactive backend and _not_ inside IPython.

warnbool, optional

print a warning if matplotlib is not running in an interactive backend and cannot display the figure, default: True.