REQ: pcolor input similar to array broadcasting

I would like to propose expanding the inputs of pcolor to take vectors. Often, you have x and y independent (seperable), and you don't want to go on constructing an x array of redundant values. Actually, in NumPy it is not straightforward to do this with resize if your variable is in the first dimension like time (well, there is meshgrid, but you would only use it for plotting, and with two vectors -- see below). Since NumPy makes such heavy use of array broadcasting, it is not necessary.

I think MPL should follow the spirit of array broadcasting, and make it such that:

x = arange(10)
y = arange(30)
z = rand(30,10)
pcolor (x, y, z)

will work as expected. Perhaps, we could require a NewAxis in the right places, but it would also make sense without. You should also be able to send in just one vector. Consider

x,y = meshgrid(arange(10), arange(30))
y = y + random.normal(size=y.shape)
z = random.random(y.shape)
pcolor (x, y, z)
% but x is still essentially just arange(10)
pcolor(arange(10), y, z)

What do you all think?

-Rob.

···

-----
Rob Hetland, Assistant Professor
Dept of Oceanography, Texas A&M University
p: 979-458-0096, f: 979-845-6331
e: hetland@...760..., w: http://pong.tamu.edu

Rob,

This is now in svn, for pcolor only, not for pcolormesh. Please check it out. If everything is OK I can add it to pcolormesh as well (although pcolormesh still has a deeply-buried bug such that it does not work with alpha != 1).

Eric

Robert Hetland wrote:

···

I would like to propose expanding the inputs of pcolor to take vectors. Often, you have x and y independent (seperable), and you don't want to go on constructing an x array of redundant values. Actually, in NumPy it is not straightforward to do this with resize if your variable is in the first dimension like time (well, there is meshgrid, but you would only use it for plotting, and with two vectors -- see below). Since NumPy makes such heavy use of array broadcasting, it is not necessary.

I think MPL should follow the spirit of array broadcasting, and make it such that:

x = arange(10)
y = arange(30)
z = rand(30,10)
pcolor (x, y, z)

will work as expected. Perhaps, we could require a NewAxis in the right places, but it would also make sense without. You should also be able to send in just one vector. Consider

x,y = meshgrid(arange(10), arange(30))
y = y + random.normal(size=y.shape)
z = random.random(y.shape)
pcolor (x, y, z)
% but x is still essentially just arange(10)
pcolor(arange(10), y, z)

What do you all think?

-Rob.

-----
Rob Hetland, Assistant Professor
Dept of Oceanography, Texas A&M University
p: 979-458-0096, f: 979-845-6331
e: hetland@...760..., w: http://pong.tamu.edu

Talking about pcolormesh:
I was just playing with it right now, and it doesn't accept the 'shading'
keyword. Poking around shows that kwargs.pop('shading','flat') should be
used instead of kwargs.get('shading') in axes.py (same goes for the other
parameters...)

Pierre GM wrote:

Talking about pcolormesh:
I was just playing with it right now, and it doesn't accept the 'shading' keyword. Poking around shows that kwargs.pop('shading','flat') should be used instead of kwargs.get('shading') in axes.py (same goes for the other parameters...)

Thanks. I have fixed this in svn and added the same X,Y argument handling that I added to pcolor yesterday.

Now, if we could only fix the alpha bug, pcolormesh could probably replace pcolor entirely. It is much faster for large arrays. There is a problem similar to one recently pointed out in imshow, however: zooming in to a small piece of a large array gets very slow. Pcolor seems to simply stay slow (maybe speeds up a little) rather then get slower as one zooms in. I think we should be able to speed up zooming, but I have not looked to see how this might be done. (Imshow is nice and fast when displaying and zooming until it runs into the odd problem of fading out and/or turning white, which coincides with getting slow.) I haven't played with NonUniformImage yet.

Eric