pyrfu.plot package#

pyrfu.plot.add_position(ax: Axes, r_xyz: DataArray, spine: float = 20, position: str = 'top', fontsize: float = 10) Axes[source]#

Add extra axes to plot spacecraft position.

Parameters:
  • ax (matplotlib.axes._axes.Axes) – Axis where to label the spacecraft position.

  • r_xyz (xarray.DataArray) – Time series of the spacecraft position.

  • spine (float, Optional) – Relative position of the axes. Default is 20.

  • position (str, Optional) – Axis position wtr to the reference axis. Default is “top”.

  • fontsize (float, Optional) – xticks label font size. Default is 10.

Returns:

axr – Twin axis with spacecraft position as x-axis label.

Return type:

matplotlib.axes._axes.Axes

pyrfu.plot.annotate_heatmap(im, data: ndarray | List[List[float]] | None = None, valfmt: str = '{x:.2f}', textcolors: tuple = ('black', 'white'), threshold: float | None = None, **textkw)[source]#

Annotate a heatmap.

Parameters:
  • im (matplotlib.image.AxesImage) – The AxesImage to be labeled.

  • data (array_like, Optional) – Data used to annotate. If None, the image’s data is used.

  • valfmt (str or matplotlib.ticker.Formatter, Optional) – The format of the annotations inside the heatmap..

  • textcolors (dict, Optional) – A pair of colors. The first is used for values below a threshold, the second for those above.

  • threshold (float, Optional) – Value in data units according to which the colors from textcolors are applied. If None (the default) uses the middle of the colormap as separation.

  • **textkw – All other arguments are forwarded to each call to text used to create the text labels.

Returns:

texts – Cells labels

Return type:

list

pyrfu.plot.colorbar(mappable, axis, pad: float = 0.01)[source]#

Add colorbar to ax corresponding to im.

Parameters:
  • mappable (matplotlib.collections.QuadMesh) – The quadrilateral mesh mappable described by this colorbar.

  • axis (matplotlib.pyplot.subplotsaxes) – Axis of plot.

  • pad (float, Optional) – Shift the colorbar with respect to the axis.

Returns:

cax – Colorbar added to the plot.

Return type:

matplotlib.colorbar.Colorbar

pyrfu.plot.make_labels(axs, pos, pad: float = 0, **kwargs)[source]#

Add subplots labels to axes

Parameters:
  • axs (ndarray) – Array of subplots axes.

  • pos (array_like) – Position of the text in the axis.

Returns:

axs – Array of subplots axes with labels.

Return type:

ndarray

pyrfu.plot.mms_pl_config(r_mms)[source]#

Plot spacecraft configuaration with three 2d plots of the position in Re and one 3d plot of the relative position of the spacecraft:

Parameters:

r_mms (list of xarray.DataArray) – Time series of the spacecraft position

Returns:

  • fig (matplotlib.pyplot.figure) – Figure with MMS configuration plot.

  • axs (matplotlib.pyplot.subplotsaxes) – Axes in the figure.

pyrfu.plot.pl_scatter_matrix(inp1, inp2: DataArray | None = None, pdf: bool = False, cmap: str = 'jet')[source]#

Produces a scatter plot of each components of field inp1 with respect to every component of field inp2. If pdf is set to True, the scatter plot becomes a 2d histogram.

Parameters:
  • inp1 (xarray.DataArray) – First time series (x-axis).

  • inp2 (xarray.DataArray) – Second time series (y-axis).

  • pdf (bool, Optional) – Flag to plot the 2d histogram. If False the figure is a scatter plot. If True the figure is a 2d histogram.

  • cmap (str, Optional) – Colormap. Default : “jet”

Returns:

  • fig (matplotlib.pyplot.figure) – Figure with time series plots.

  • axs (matplotlib.axes._subplots.AxesSubplot) – Axes.

  • caxs (matplotlib.pyplot.colorbar) – Only if pdf is True

pyrfu.plot.pl_tx(axis: Axes, inp_list: List[DataArray], comp: int = 0, colors: str = 'mms', **kwargs) Axes[source]#

Line plot of 4 spacecraft time series.

Parameters:
  • axis (matplotlib.axes._axes.Axes) – Axis

  • inp_list (list of xarray.DataArray) – Time series to plot

  • comp (int, Optional) – Index of the column to plot. Default is 0.

  • colors ({'cluster', 'mms'}, Optional) – Color cycle to use. Default uses MMS

  • kwargs (dict) – Hash table of plot options.

Returns:

axis – Axis with matplotlib.lines.Line2D.

Return type:

matplotlib.axes._axes.Axes

Raises:

NotImplementedError – if invalid color style of inp_list.ndim > 3:

pyrfu.plot.plot_ang_ang(vdf, tint: list | None = None, en_range: list | None = None)[source]#

Creates colormap of the phase space density or the differential particle flux, as a function of the azimuthal and elevation angles.

Parameters:
  • vdf (xarray.Dataset) – Skymap distribution.

  • tint (list of str, Optional) – Time interval. If the time interval contains only one element, uses the distribution at the closest time. If the time interval contains two elements, time average the distribution. If None, uses the entire timeline for averaging. Default is None.

  • en_range (list of float, Optional) – Energy range. If None uses the entire energy range.

Returns:

  • f (matplotlib.figure.Figure) – Figure

  • ax (matplotlib.axes._subplots.AxesSubplot) – Axis

  • cax (matplotlib.axes._axes.Axes) – Colorbar axis

pyrfu.plot.plot_clines(axis, inp, yscale='log', cscale='log', cmap='jet', **kwargs)[source]#

Plot lines with color associated to the level.

Parameters:
  • axis – Axes

  • inp (xarray.DataArray) – Time series as an energy spectrum to plot.

  • yscale (str, Optional) – Scale of the yaxis. Default is “log”

  • cscale (str, Optional) – Scale of the colormap. Default is “log”.

  • cmap (str, Optional) – Colormap. Default is “jet”

  • kwargs (dict) – Plot options.

  • pyrfu.plot.plot_line (See) –

Returns:

  • axis – Updated axis

  • cbl – Colorbar associated

pyrfu.plot.plot_heatmap(ax: Axes, data: ndarray | List[List[float]], row_labels: ndarray | List[str], col_labels: ndarray | List[str], cbar_kw: dict | None = None, cbarlabel: str = '', **kwargs) Tuple[AxesImage, Colorbar][source]#

Create a heatmap from a numpy array and two lists of labels.

Parameters:
  • ax (matplotlib.axes._axes.Axes) – Axis to which the heatmap is plotted.

  • data (array_like) – A 2D numpy array of shape (N, M).

  • row_labels (list or numpy.ndarray) – A list or array of length N with the labels for the rows.

  • col_labels (list or numpy.ndarray) – A list or array of length M with the labels for the columns.

  • cbar_kw (dict, Optional) – A dictionary with arguments to matplotlib.Figure.colorbar.

  • cbarlabel (str, Optional) – The label for the colorbar.

  • **kwargs – All other arguments are forwarded to imshow.

Returns:

  • im (matplotlib.image.AxesImage) – The AxesImage of the data.

  • cbar (matplotlib.colorbar.Colorbar) – Colorbar.

pyrfu.plot.plot_line(axis, inp, **kwargs)[source]#

Line plot of time series.

Parameters:
  • axis (matplotlib.axes._axes.Axes) – Single axis where to plot inp. If None creates a new figure with a single axis.

  • inp (xarray.DataArray) – Time series to plot

  • **kwargs – Keyword arguments control the line properties. See matplotlib.lines.Line2D for reference.

Returns:

axs – Axis with matplotlib.lines.Line2D.

Return type:

matplotlib.axes._axes.Axes

pyrfu.plot.plot_magnetosphere(ax, tint, colors: list | None = None, field_lines: bool = True)[source]#

Plot magnetopause, bow shock and earth.

Parameters:
  • ax (matplotlib.pyplot.subplotsaxes) – Axis to plot.

  • tint (list of str) – Time interval.

  • colors (list, Optional) – Colors of the magnetopause and the bow show. Default use [“tab:blue”, “tab:red”]

Returns:

ax – Axis.

Return type:

matplotlib.pyplot.subplotsaxes

pyrfu.plot.plot_projection(axis, v_x, v_y, f_mat, vlim: float = 1000.0, clim: list | None = None, cmap: str | None = None, colorbar: str = 'right')[source]#

Plot the projection of the distribution.

Parameters:
  • axis (matplotlib.pyplot.subplotsaxes) – Axis to plot.

  • v_x (ndarray) – X axis velocity grid.

  • v_y (ndarray) – Y axis velocity grid.

  • f_mat (ndarray) – Projected distribution.

  • vlim (float, Optional) – Maximum velocity to limit axis. Default is vlim = 1000 km/s.

  • clim (list, Optional) – Caxes limit. Default is clim = [-18, -13] (assume to be in SI units)

  • colorbar (str, Optional) – Location of the colorbar. Default is cbar_pos = “top”.

  • cmap (str, Optional) – Colormap. Default is cmap = “jet”.

Returns:

  • axis (axis) – Axis

  • caxis (axis) – Colorbar axis.

pyrfu.plot.plot_reduced_2d(ax, f2d, clim: list | None = None)[source]#

Plot the 2D recuded distribution f2d onto the axis ax.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – Axis.

  • f2d (xarray.DataArray) – 2D reduced distribution.

  • clim (list of floats, Optional) – Coloraxis limits.

Returns:

  • ax (matplotlib.axes._subplots.AxesSubplot) – Axis.

  • cax (matplotlib.axes._axes.Axes) – Colorbar axis.

pyrfu.plot.plot_spectr(axis, inp, yscale: str = 'linear', cscale: str = 'linear', clim: list | None = None, cmap: str | None = None, colorbar: str = 'right', **kwargs)[source]#

Plot a spectrogram using pcolormesh.

Parameters:
  • axis (matplotlib.pyplot.subplotsaxes) – Target axis to plot. If None create a new figure.

  • inp (xarray.DataArray) – Input 2D data to plot.

  • yscale ({"linear", "log"}, Optional) – Y-axis scaling. Default is “” (linear).

  • cscale ({"linear", "log"}, Optional) – C-axis scaling. Default is “” (linear).

  • clim (list, Optional) – C-axis bounds. Default is None (autolim).

  • cmap (str, Optional) – Colormap. Default is “jet”.

  • colorbar (str, Optional) – Location of the colorbar with respect to the axis. Set to “none” to hide.

  • **kwargs – Keyword arguments.

Returns:

  • fig (figure) – Figure with axis.

  • axs (matplotlib.pyplot.subplotsaxes) – Axis with spectrum.

  • caxs (matplotlib.pyplot.subplotsaxes) – Only if colorbar is True.

pyrfu.plot.plot_surf(axis, x, y, z, c, cmap, norm, cax_pos: str = 'bottom')[source]#

Plots surface.

Parameters:
  • axis (matplotlib.axes._subplots.Axes3DSubplot) – Axis to plot.

  • x (ndarray) – X axis meshgrid.

  • y (ndarray) – Y axis meshgrid.

  • z (ndarray) – Z axis meshgrid.

  • c (ndarray) – C axis meshgrid.

  • cmap (matplotlib.colors.ListedColormap) – Colormap

  • norm (matplotlib.colors.Normalize) – Normalization.

  • cax_pos ({"bottom", "top", "left", "right"}, Optional) – Position of the colorbar with respect to the axis. Default is “bottom”.

Returns:

  • axis (matplotlib.axes._subplots.Axes3DSubplot) – Axis with surface.

  • caxis (matplotlib.axes._axes.Axes) – Colorbar axis.

pyrfu.plot.set_color_cycle(pal: str = '') -> (<class 'list'>, <class 'str'>)[source]#

Sets color cycle.

Parameters:

pal ({"Pyrfu", "Oceanic", "Tab", ""}. Optional) – The palette to use. “Tab” provides the default matplotlib palette. Default is “” (resets to default palette).

pyrfu.plot.span_tint(axs, tint, ymin: float = 0, ymax: float = 1, **kwargs)[source]#

Add a vertical span (rectangle) across the time Axes.

The rectangle spans from tint[0] to tint[1] horizontally, and, by default, the whole y-axis vertically. The y-span can be set using ymin (default: 0) and ymax (default: 1) which are in axis units; e.g. ymin = 0.5 always refers to the middle of the y-axis regardless of the limits set by set_ylim

Parameters:
  • axs (list of matplotlib.pyplot.subplotsaxes) – Axes to span.

  • tint (list of str) – Time interval to span

  • ymin (float) – Lower y-coordinate of the span, in y-axis units (0-1). Default ymin=0.

  • ymax (float, Optional) – Upper y-coordinate of the span, in y-axis units (0-1). Default ymax=1.

  • **kwargs – Keyword arguments control the Polygon properties.

Returns:

axs – List of matplotlib.axes._subplots.AxesSubplot spanned..

Return type:

list

pyrfu.plot.use_pyrfu_style(name: str = 'default', color_cycle: str = 'pyrfu', fancy_legend: bool = False, usetex: bool = False)[source]#

Setup plot style.

Parameters:
  • name (str, Optional) – Name of the style sheet. Default is “default” (see also https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html).

  • color_cycle (str, Optional) – Name of the color cycle to use. Default is “pyrfu”.

  • fancy_legend (bool, Optional) – Use matplotlib’s fancy legend frame. Default is False.

  • usetex (bool, Optional) – Use LaTeX installation to set text. Default is False. If no LaTeX installation is found, this package will fallback to usetex=False.

pyrfu.plot.zoom(ax1: ~matplotlib.axes._axes.Axes, ax2: ~matplotlib.axes._axes.Axes, **kwargs) -> (<class 'matplotlib.axes._axes.Axes'>, <class 'matplotlib.axes._axes.Axes'>)[source]#

Similar to zoom_effect01. The xmin & xmax will be taken from the ax1.viewLim.

Parameters:
Returns:

  • ax1 (matplotlib.axes._axes.Axes) – Reference axis.

  • ax2 (matplotlib.axes._axes.Axes) – Connected axis.

Submodules#