pcolormesh#

named_arrays.plt.pcolormesh(*XY, C, axis_rgb=None, ax=None, components=None, cmap=None, norm=None, vmin=None, vmax=None, **kwargs)#

A thin wrapper around matplotlib.pyplot.pcolormesh() for named arrays.

Parameters:
  • XY (AbstractArray) – The coordinates of the mesh. If C is a scalar, XY can either be two scalars or one vector . If C is a function, XY is not specified. If XY is not specified as two scalars, the components must be given, see below.

  • C (AbstractArray) – The mesh data.

  • axis_rgb (None | str) – The optional logical axis along which the RGB color channels are distributed.

  • ax (None | Axes | AbstractArray) – The instances of matplotlib.axes.Axes to use. If None, calls matplotlib.pyplot.gca() to get the current axes. If an instance of named_arrays.ScalarArray, ax.shape should be a subset of the broadcasted shape of *args.

  • components (None | tuple[str, str]) – If XY is not specified as two scalars, this parameter should be a tuple of two strings, specifying the vector components of XY to use as the horizontal and vertical components of the mesh.

  • cmap (None | str | Colormap | AbstractArray) – The colormap used to map scalar data to colors.

  • norm (None | str | Normalize) – The normalization method used to scale data into the range [0, 1] before mapping to colors.

  • vmin (None | int | float | complex | ndarray | Quantity | AbstractArray) – The minimum value of the data range.

  • vmax (None | int | float | complex | ndarray | Quantity | AbstractArray) – The maximum value of the data range.

  • kwargs – Additional keyword arguments accepted by matplotlib.pyplot.pcolormesh

Return type:

AbstractScalar

Examples

Plot a random 2D mesh

import matplotlib.pyplot as plt
import named_arrays as na

# Define the size of the grid
shape = dict(x=16, y=16)

# Define a simple coordinate grid
x = na.linspace(-2, 2, axis="x", num=shape["x"])
y = na.linspace(-1, 1, axis="y", num=shape["y"])

# Define a random 2D array of values to plot
a = na.random.uniform(-1, 1, shape_random=shape)

# Plot the coordinates and values using pcolormesh
fig, ax = plt.subplots(constrained_layout=True)
na.plt.pcolormesh(x, y, C=a, ax=ax);
../_images/named_arrays.plt.pcolormesh_0_0.png

Plot a grid of random 2D meshes

import named_arrays as na

# Define the size of the grid
shape = dict(row=2, col=3, x=16, y=16)

# Define a simple coordinate grid
x = na.linspace(-2, 2, axis="x", num=shape["x"])
y = na.linspace(-1, 1, axis="y", num=shape["y"])

# Define a random 2D array of values to plot
a = na.random.uniform(-1, 1, shape_random=shape)

# Plot the coordinates and values using pcolormesh
fig, ax = na.plt.subplots(
    axis_rows="row",
    nrows=shape["row"],
    axis_cols="col",
    ncols=shape["col"],
    sharex=True,
    sharey=True,
    constrained_layout=True,
)
na.plt.pcolormesh(x, y, C=a, ax=ax);
../_images/named_arrays.plt.pcolormesh_1_0.png