I have a binary numpy
array that contains filling data, and two grids that define the bounding box for the data:
data = np.random.choice([0, 1], size=12).reshape((3, 4))
xGrid = np.linspace(1, 4, 4)
yGrid = np.linspace(0.1, 0.3, 3)
I would like to plot a particular color, with a particular alpha, on any grid point where data is 1
, and nothing when data is 0
. The two closest matplotlib functions are
fill
, which requires (x, y) coordinates and can't work with this dataimshow
ormatshow
, which unfortunately will plot some color everywhere. That is, it will also plot some color drawn from the color map whereverdata == 0
. Now, I could fiddle around to make that color be the background color of the ax, but that's rather nasty.
The bounding boxes are expected to behave as follows: xGrid
contains three values, and there are three data points on the x-dimension. Each value in xGrid
denotes the location of the center point for each of the data points, and similar for yGrid
. "Filling a data point" then corresponds to filling the rectangle defined by the center coordinates (x, y
).
What's the best way of achieving this?