It's quite complicated ... but I think your statement about the measurements is correct. This is due to the way pcolormesh creates the QuadMesh object.
The documentation states that:
A quadrangular grid is represented by the formula (2 x ((meshWidth + 1) * (meshHeight + 1))) numpy array
In this context, meshWidth is your xx , meshHeight is your yy . When the kernel defines an array using set_array, pcolormesh wants to interpret it directly as quadrilaterals (meshWidth x meshHeight) and therefore requires less than one in each dimension.
When I tested it, I got the following behavior: if you changed
graph.set_array(grid.ravel())
to
graph.set_array(grid[:-1,:-1].ravel())
your plot will look as it should.
In code, this is similar to the initial call to pcolormesh, if xx and yy , they should be defined as having one more point in each dimension than an array of values, and if they're not (disabled by 1), then the array is automatically trimmed to one value . Thus, you should get the same answer, even if you use grid[:-1,:-1] in the first call.
Ajean source share