differt.plotting.draw_image#
- draw_image(data, x=None, y=None, z0=0.0, **kwargs)[source]#
Plot a 2D image on a 3D canvas, at a fixed z-coordinate.
- Parameters:
data (
Real[ArrayLike, 'rows cols']|Real[ArrayLike, 'rows cols 3']|Real[ArrayLike, 'rows cols 4']) – The image data array. Can be grayscale, RGB, or RGBA. For more details on how the data is interpreted, please refer to the documentation of the function corresponding to the specified backend (see below).x (
Real[ArrayLike, 'cols']|Real[ArrayLike, 'rows cols 3']|None) – The x-coordinates corresponding to first dimension of the image. Those coordinates will be used to scale and translate the image.y (
Real[ArrayLike, 'rows']|Real[ArrayLike, 'rows cols 3']|None) – The y-coordinates corresponding to second dimension of the image. Those coordinates will be used to scale and translate the image.z0 (
float) – The z-coordinate at which the image is placed.kwargs (
Any) – Keyword arguments passed toImage,contourf, orMesh3d, depending on the backend.
- Return type:
- Returns:
The resulting plot output.
Warning
Matplotlib backend requires
datato be either an RGB or an RGBA array.Examples
The following example shows how to plot a 2-D image, without and with axis scaling.
>>> from differt.plotting import draw_image >>> >>> x = np.linspace(-1.0, +1.0, 100) >>> y = np.linspace(-4.0, +4.0, 200) >>> X, Y = np.meshgrid(x, y) >>> Z = np.sin(X) * np.cos(Y) >>> # Let's mask some values to draw a ring >>> R = np.sqrt(16 * X * X + Y * Y) >>> Z = np.where((R > 0.5) & (R < 1.5), np.nan, Z) >>> fig1 = draw_image(Z, backend="plotly") >>> fig1 >>> >>> fig2 = draw_image(Z, x=x, y=y, backend="plotly") >>> fig2