py21cmfast.plotting

Simple plotting functions for 21cmFAST objects.

Attributes

Functions

coeval_sliceplot(struct[, kind, cbar_label])

Show a slice of a given coeval box.

coeval_summary_plot(→ tuple[matplotlib.pyplot.Figure, ...)

Make a simple summary plot of a coeval cube.

get_global_quantities(→ tuple[numpy.ndarray, dict[str, ...)

Get the redshifts and global quantities of a lightcone or global evolution.

lightcone_sliceplot(lightcone[, kind, lightcone2, ...])

Create a 2D plot of a slice through a lightcone.

lightcone_summary_plot(...)

Make a simple summary plot of a lightcone.

plot_global_evolution(...)

Plot a default set of global (mean) quantities as a function of redshift.

plot_global_history(lightcone[, kind, ylabel, ylog, ...])

Plot the global history of a given quantity from a lightcone.

plot_global_signal(→ tuple[matplotlib.pyplot.Figure, ...)

Plot the global 21-cm signal as a function of redshift.

summary_plot(→ tuple[matplotlib.pyplot.Figure, ...)

Make a simple default summary plot of a 21cmFAST simulation output.

Module Contents

py21cmfast.plotting.coeval_sliceplot(struct: py21cmfast.wrapper.outputs._OutputStruct | py21cmfast.drivers.coeval.Coeval, kind: str | None = None, cbar_label: str | None = None, **kwargs)[source]

Show a slice of a given coeval box.

Parameters:
  • struct (_OutputStruct or Coeval instance) – The output of a function such as ionize_box (a class containing several quantities), or run_coeval.

  • kind (str or nd-array) –

    If str: The quantity within the structure to be shown. A full list of available options

    can be obtained by running Coeval.get_fields().

    If nd-array: A 3D box to be shown. This could be useful for plotting the coeval brightness temperature box

    after redshift space distortions have been applied.

  • cbar_label (str, optional) – A label for the colorbar. Some values of kind will have automatically chosen labels, but these can be turned off by setting cbar_label=''.

Returns:

fig, ax – figure and axis objects from matplotlib

Other Parameters:
  • All other parameters are passed directly to :func:`_imshow_slice`. These include `slice_axis`

  • and `slice_index`,

  • which choose the actual slice to plot, optional `fig` and `ax` keywords which enable

  • over-plotting previous figures,

  • and the `imshow_kw` argument, which allows arbitrary styling of the plot.

Parameters:
py21cmfast.plotting.coeval_summary_plot(coeval: py21cmfast.drivers.coeval.Coeval, kinds: collections.abc.Sequence[str] | None = None, slice_index: int | None = None, log: bool | None = None, **kwargs) → tuple[matplotlib.pyplot.Figure, list[matplotlib.pyplot.Axes]][source]

Make a simple summary plot of a coeval cube.

This plots a slice through the box for each of a default set of fields, as a quick visual check that the simulation ran as expected.

Parameters:
  • coeval – The Coeval object to plot.

  • kinds – The fields to plot. By default, whichever of brightness_temp, neutral_fraction, density and spin_temperature are available.

  • slice_index – The index of the slice to plot. By default, the middle of the box.

  • log – Whether to use a logarithmic color scale. By default, chosen per-field: fields spanning several orders of magnitude (e.g. the temperatures) are plotted logarithmically, provided they are everywhere positive. These fields also have their color scale clipped to their 1st-99th percentile range, unless you pass explicit vmin/vmax.

  • kwargs – Passed through to coeval_sliceplot().

Returns:

fig, axes – The matplotlib Figure and list of Axes objects.

Parameters:
Return type:

tuple[matplotlib.pyplot.Figure, list[matplotlib.pyplot.Axes]]

py21cmfast.plotting.get_global_quantities(obj) → tuple[numpy.ndarray, dict[str, numpy.ndarray]][source]

Get the redshifts and global quantities of a lightcone or global evolution.

Parameters:

obj – Either a LightCone or a GlobalEvolution.

Returns:

  • redshifts – The node redshifts of the simulation.

  • quantities – A dictionary of global (i.e. mean) quantities at each node redshift.

Return type:

tuple[numpy.ndarray, dict[str, numpy.ndarray]]

py21cmfast.plotting.lightcone_sliceplot(lightcone: py21cmfast.drivers.lightcone.LightCone, kind: str = 'brightness_temp', lightcone2: py21cmfast.drivers.lightcone.LightCone = None, vertical: bool = False, xlabel: str | None = None, ylabel: str | None = None, cbar_label: str | None = None, zticks: str = 'redshift', fig: matplotlib.pyplot.Figure | None = None, ax: matplotlib.pyplot.Axes | None = None, z_range=None, **kwargs)[source]

Create a 2D plot of a slice through a lightcone.

Parameters:
  • lightcone (Lightcone) – The lightcone object to plot

  • kind (str, optional) – The attribute of the lightcone to plot. Must be an array.

  • lightcone2 (str, optional) – If provided, plot the _difference_ of the selected attribute between the two lightcones.

  • vertical (bool, optional) – Whether to plot the redshift in the vertical direction.

  • cbar_label (str, optional) – A label for the colorbar. Some quantities have automatically chosen labels, but these can be removed by setting cbar_label=’’.

  • zticks (str, optional) – Defines the co-ordinates of the ticks along the redshift axis. Can be “redshift” (default), “frequency”, “distance” (which starts at zero for the lowest redshift) or the name of any function in an astropy cosmology that is purely a function of redshift.

  • kwargs – Passed through to imshow().

Returns:

  • fig – The matplotlib Figure object

  • ax – The matplotlib Axis object onto which the plot was drawn.

Parameters:
py21cmfast.plotting.lightcone_summary_plot(lightcone: py21cmfast.drivers.lightcone.LightCone, kind: str = 'brightness_temp', panels: collections.abc.Sequence[str] | None = None, width: float = 9.0, panel_height: float = 1.8, **kwargs) → tuple[matplotlib.pyplot.Figure, list[matplotlib.pyplot.Axes]][source]

Make a simple summary plot of a lightcone.

The top panel is a slice through the lightcone, and the panels below show the global evolution of a default set of quantities. All panels share the same line-of-sight axis, so that features can be matched up by eye.

Parameters:
  • lightcone – The LightCone to plot.

  • kind – The lightcone field to show in the top panel.

  • panels – Which global-evolution panels to show below the lightcone. See plot_global_evolution().

  • width – The width of the figure, in inches.

  • panel_height – The height of each global-evolution panel, in inches.

  • kwargs – Passed through to lightcone_sliceplot().

Returns:

fig, axes – The matplotlib Figure and list of Axes objects. The first is the lightcone slice, the rest are the global-evolution panels.

Parameters:
Return type:

tuple[matplotlib.pyplot.Figure, list[matplotlib.pyplot.Axes]]

py21cmfast.plotting.plot_global_evolution(obj, panels: collections.abc.Sequence[str] | None = None, fig: matplotlib.pyplot.Figure | None = None, axes: collections.abc.Sequence[matplotlib.pyplot.Axes] | None = None, frequency_axis: bool = True, **kwargs) → tuple[matplotlib.pyplot.Figure, list[matplotlib.pyplot.Axes]][source]

Plot a default set of global (mean) quantities as a function of redshift.

This is a simple summary plot, giving a quick overview of a simulation: the global 21-cm signal, the ionization history and the temperature history (whichever of these are available in the given object).

Parameters:
  • obj – A LightCone or GlobalEvolution object.

  • panels – Which panels to plot. By default, all of “signal”, “ionization” and “temperature” that have data available.

  • fig, axes – Optional pre-existing figure/axes on which to plot. If given, there must be at least as many axes as panels.

  • frequency_axis – Whether to add a secondary axis at the top of the figure showing the observed frequency of the 21-cm line.

  • kwargs – Passed through to ax.plot().

Returns:

  • fig – The matplotlib Figure object.

  • axes – The list of matplotlib Axes objects that were drawn onto.

Parameters:
  • panels (collections.abc.Sequence[str] | None)

  • fig (matplotlib.pyplot.Figure | None)

  • axes (collections.abc.Sequence[matplotlib.pyplot.Axes] | None)

  • frequency_axis (bool)

Return type:

tuple[matplotlib.pyplot.Figure, list[matplotlib.pyplot.Axes]]

py21cmfast.plotting.plot_global_history(lightcone: py21cmfast.drivers.lightcone.LightCone, kind: str | None = None, ylabel: str | None = None, ylog: bool = False, ax: matplotlib.pyplot.Axes | None = None, zmax: float | None = None, **kwargs)[source]

Plot the global history of a given quantity from a lightcone.

Parameters:
  • lightcone (LightCone or GlobalEvolution instance) – The object containing the quantity to plot.

  • kind (str, optional) – The quantity to plot. Must be one of the global quantities of the given object. By default, will choose the first one.

  • ylabel (str, optional) – A y-label for the plot. If None, will use kind.

  • ylog (bool, optional) – Whether to use a logarithmic y-axis.

  • ax (Axes, optional) – The matplotlib Axes object on which to plot. Otherwise, created.

  • zmax (float, optional) – If given, only plot redshifts below this value.

Parameters:
py21cmfast.plotting.plot_global_signal(obj, ax: matplotlib.pyplot.Axes | None = None, frequency_axis: bool = True, **kwargs) → tuple[matplotlib.pyplot.Figure, matplotlib.pyplot.Axes][source]

Plot the global 21-cm signal as a function of redshift.

Parameters:
  • obj – A LightCone or GlobalEvolution object.

  • ax – The matplotlib Axes on which to plot. Created by default.

  • frequency_axis – Whether to add a secondary axis at the top showing the observed frequency of the 21-cm line.

  • kwargs – Passed through to ax.plot().

Returns:

fig, ax – The matplotlib Figure and Axes objects.

Parameters:
  • ax (matplotlib.pyplot.Axes | None)

  • frequency_axis (bool)

Return type:

tuple[matplotlib.pyplot.Figure, matplotlib.pyplot.Axes]

py21cmfast.plotting.summary_plot(obj, **kwargs) → tuple[matplotlib.pyplot.Figure, list[matplotlib.pyplot.Axes]][source]

Make a simple default summary plot of a 21cmFAST simulation output.

The plot produced depends on the type of obj: see coeval_summary_plot(), lightcone_summary_plot() and plot_global_evolution().

Parameters:
  • obj – A Coeval, LightCone or GlobalEvolution object.

  • kwargs – Passed through to the relevant plotting function.

Returns:

fig, axes – The matplotlib Figure and list of Axes objects.

Return type:

tuple[matplotlib.pyplot.Figure, list[matplotlib.pyplot.Axes]]

py21cmfast.plotting.eor_colour[source]
py21cmfast.plotting.logger[source]