John Hunter wrote:
"Petr" == Petr Danecek <[EMAIL PROTECTED]> writes:
[...]
Petr> 2) When set_aspect() is used, the size of colorbar does not
Petr> respect y-dimension of the graph. (See the attached
Petr> example.) Is it possible to set the size of the colorbar
Petr> directly?
Examples of the shrink kwarg are examples/image_masked.py and
examples/contour_demo.py.
As an alternative to using the shrink kwarg you can always specify axes
positions manually. One example is in examples/multi_image.py.
Attached is another example modified from image_masked.py.
One of the examples shows how to do this if I recall correctly, but I
don't remember which one. Eric Firing wrote it so I'm sure he'll be
along shortly to point you to the light. Eric -- perhaps we should
also add a snippet to the colorbar docstring since this is a common
request.
I have added a bit to the docstring to emphasize the function of the
shrink kwarg. This will usually be the easiest manual solution to the
problem. I have also thought a bit about adding functionality to the
axes.draw() method that would allow the colorbar height to track the
height of the mappable axes object; maybe I will try it later.
Eric
#!/usr/bin/env python
'''imshow with masked array input and out-of-range colors.
'''
from pylab import *
import matplotlib.numerix.ma as ma
import matplotlib.colors as colors
delta = 0.025
x = y= arange(-3.0, 3.0, delta)
X, Y = meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = 10 * (Z2-Z1) # difference of Gaussians
# Set up a colormap:
palette = cm.gray
palette.set_over('r', 1.0)
palette.set_under('g', 1.0)
palette.set_bad('b', 1.0)
# Alternatively, we could use
# palette.set_bad(alpha = 0.0)
# to make the bad region transparent. This is the default.
# If you comment out all the palette.set* lines, you will see
# all the defaults; under and over will be colored with the
# first and last colors in the palette, respectively.
Zm = ma.masked_where(Z > 1.2, Z)
# By setting vmin and vmax in the norm, we establish the
# range to which the regular palette color scale is applied.
# Anything above that range is colored based on palette.set_over, etc.
fig = figure()
axi = fig.add_axes([0.1, 0.1, 0.7, 0.8])
im = axi.imshow(Zm, interpolation='bilinear',
cmap=palette,
norm = colors.Normalize(vmin = -1.0, vmax = 1.0, clip = False),
origin='lower', extent=[-3,3,-1,1])
title('Green=low, Red=high, Blue=bad')
axcb = fig.add_axes([0.85, 0.35, 0.02, 0.3])
fig.colorbar(im, cax=axcb, extend='both')
show()
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users