How do I set a matplotlib colorbar extents?

Posted by Adam Fraser on Stack Overflow See other posts from Stack Overflow or by Adam Fraser
Published on 2010-03-29T15:53:27Z Indexed on 2010/03/29 16:33 UTC
Read the original article Hit count: 400

Filed under:
|

I'd like to display a colorbar representing an image's raw values along side a matplotlib imshow subplot which displays that image, normalized.

I've been able to draw the image and a colorbar successfully like this, but the colorbar min and max values represent the normalized (0,1) image instead of the raw (0,99) image.

f = plt.figure()
# create toy image
im = np.ones((100,100))
for x in range(100):
    im[x] = x
# create imshow subplot
ax = f.add_subplot(111)
result = ax.imshow(im / im.max())

# Create the colorbar
axc, kw = matplotlib.colorbar.make_axes(ax)
cb = matplotlib.colorbar.Colorbar(axc, result)

# Set the colorbar
result.colorbar = cb

If someone has a better mastery of the colorbar API, I'd love to hear from you.

Thanks! Adam

© Stack Overflow or respective owner

Related posts about python

Related posts about matplotlib