Colormap norm (vmin, vmax) based on visible part of figure

Hi all,

I’m wondering if anyone knows how to compute colorbar limits (vmin, vmax) based only on the visible portion of the figure. My use-case is a pcolormesh(x, y, z) drawn over a Basemap instance. The coordinates x and y cover the entire globe, but I’m only mapping the Arctic. What happens is that the normalization is done over the entire z array, while only a subset of z actually appears on the map. The colors appearing on the map thus cover only a small fraction of the entire color range.

From what I managed to understand, pcolormesh creates a collections of patches colorcoded based on the array attribute. So my question is if there is a builtin way to know which items of this collections are clipped so I can mask this part of the array ?

Thanks a lot,

David

As far as I know, no, there is not a built-in way of doing so. There is the clipping mechanism to prevent drawing things outside of bounding boxes (used for easy zooming and panning among other things), but as far as I know, that is done mostly in the backends, and it doesn’t provide information on which elements in the array was chosen drawn. I would suggest making a feature request on the github page, and hopefully, someone will have an epiphany on how to implement such a feature (maybe with the scalar mappable objects?).

Cheers!
Ben Root

···

On Sun, Dec 16, 2012 at 4:41 PM, David Huard <david.huard@…287…> wrote:

Hi all,

I’m wondering if anyone knows how to compute colorbar limits (vmin, vmax) based only on the visible portion of the figure. My use-case is a pcolormesh(x, y, z) drawn over a Basemap instance. The coordinates x and y cover the entire globe, but I’m only mapping the Arctic. What happens is that the normalization is done over the entire z array, while only a subset of z actually appears on the map. The colors appearing on the map thus cover only a small fraction of the entire color range.

From what I managed to understand, pcolormesh creates a collections of patches colorcoded based on the array attribute. So my question is if there is a builtin way to know which items of this collections are clipped so I can mask this part of the array ?

Thanks a lot,

David