From: John H. <jdh...@ac...> - 2005-03-16 18:35:43
|
>>>>> "James" == James Boyle <bo...@ll...> writes: James> How would one get a colorbar() with a matshow plot? That James> 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 [1]: matshow(rand(12,12)) In [2]: 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 fig.hbox.add(ax) fig.hbox.add(cax) 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 |