Question

I am doing a very simple task of plotting a 2d numpy histogram and displaying with with

mayavi.mlab.imshow(my2dhistogram, interpolate=False)

For a 5x5 array the output is the following,

enter image description here

I would like the bins along the border to be the same size as the ones in the center. I understand the logic of what mayavi is doing but for this application I absolutely need the bins to be equal size. This is for a scientific visualization where each bin represents a measurement on a detector surface.

Any suggestions?

Was it helpful?

Solution

I don't know how to do this the right way (it seems like it would be very difficult to get right from what I know about imshow), but I have a conceptual suggestion.

Represent your NxN matrix of items on the surface with an (N+2)x(N+2) matrix and set the border entries to be -1. Then make a customized colormap such that your desired colormap is contained between 0 and 1, with all other entries as (0,0,0,0). I'm not exactly sure how to do that -- iirc mayavi modules don't allow you to setup discontinuous color tables, but you could still hack it in this way. Let me know if the part about the color table is confusing, and I can provide some code to make it work.

Also, is there a reason you need to use mayavi's imshow as opposed to say matplotlib for this essentially 2D problem?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top