 # colorbar with matshow plot?

How would one get a colorbar() with a matshow plot? That

> is without altering the matshow code in pylab.,py.

A good question. The naive answer is: add the gci._current line to
the matshow code below the imshow line

im = ax.imshow(*args,**kw)
gci._current = im

and then do

In : matshow(rand(12,12))
In : colorbar()

The problem, of course, is that colorbar resizes the current axes,
which defeats the purpose of matshow.

What one needs is a colorbar kwarg to the matshow function that makes
extra room for the colorbar and still preserves the aspect ratio.
This would require some arithmetic and extra work. Any takers?

Perry and I have been discussing some ideas to make this kind of
layout easier. The problem is that the figure size is picked first,
and the axes are fractions of that. In addition to the current
functionality, it would be nice to have a figure container that
resized itself, and axes that were in physical sizes. Eg, something
like

fig = FigureDynamic()
ax = AxesSized(5,5) # inches
cax = AxesSized(.5,5) # inches
X = rand(12,12)
ax.imshow(X) # aspect ratio is correct since axwidth=axheight
fig.colorbar(cax)

When you add the axes, the figure window would resize itself to
accommodate them, which is the inverse of what happens currently --
the axes physical dimensions resize themselves according to the figure
physical size. I think both approaches are useful.

JDH

John Hunter wrote:

"James" == James Boyle <boyle5@...99...> writes:

> How would one get a colorbar() with a matshow plot? That
> is without altering the matshow code in pylab.,py.

A good question. The naive answer is: add the gci._current line to
the matshow code below the imshow line

im = ax.imshow(*args,**kw)
gci._current = im

and then do

In : matshow(rand(12,12))
In : colorbar()

The problem, of course, is that colorbar resizes the current axes,
which defeats the purpose of matshow.

What one needs is a colorbar kwarg to the matshow function that makes
extra room for the colorbar and still preserves the aspect ratio.
This would require some arithmetic and extra work. Any takers?

Well, I've been wanting this (I mentioned it to you in SF in passing) for a while. But I don't know the sizing code well enough to be able to write it up quickly. I'm just not terribly comfortable yet with the overall internal design of mpl. If nobody else does it I probably will, because I need it. But it will likely be _weeks_ before I even have a look.

best,

f