cachai.utilities.colormapped_patch

cachai.utilities.colormapped_patch(patch, map_matrix, ax=None, colormap='coolwarm', zorder=5, alpha=0.5, rasterized=False)[source]

Applies a colormap to a patch object using a precomputed map matrix, creating a color-filled shape.

Parameters
patchmatplotlib.patches.Patch and similar

Matplotlib patch object to be filled with colors.

map_matrixnumpy.ndarray

2D array containing color values for the mapping.

Returns

matplotlib.image.AxesImage

Other Parameters
axmatplotlib.axes.Axes

Axes object where the patch will be drawn (default: current axes).

colormapstr or matplotlib.colors.LinearSegmentedColormap

Matplotlib colormap to use.

zorderint

Rendering order layer for the patch.

alphafloat

Transparency level of the filled patch.

rasterizedbool

Whether to rasterize the patch for better performance.

Examples

import cachai.utilities as chu
import numpy as np
import matplotlib.pyplot as plt
from   matplotlib.patches import Circle

# Create a circular patch
circle = Circle((0.5, 0.5), 0.3)
# Generate a simple gradient map
gradient = np.linspace(-1, 1, 400).reshape(20, 20)

fig, ax = plt.subplots()
ax.add_patch(circle)
chu.colormapped_patch(circle, gradient, ax=ax)
plt.show()