 # colorbar rescaling

Hi,

I hope someone can answer this colorbar related question.

I have a plot, to which I am drawing a colorbar. The standard colorbar ranges from the values -1 (blue) over 0 (green) to e.g. 1(red). So far so good.

But now I want to change the colorbar that it shows only the colors between 0 and 1. What I mean is: the colorbar should start at value 0 (with green) and go to 1(red), and leave the original plot unchanged.
I ad some example code below to make it more clear. In the example plot created, only the values between 0 and 1 are interesting and should be shown in the colorbar, but not -1 (blue). But I want the original plot unchanged!

If anyone has an idea that would be great.

Cheers
Alex

import numpy as np
import matplotlib
import pylab as py

f = py.figure()

# create toy image

im = -np.ones((100,100))

for x in range(20,80):
for y in range(20,80):
im[x,y] = random.random()

# create imshow subplot

result = ax.imshow(im)

# Create the colorbar

axc, kw = matplotlib.colorbar.make_axes(ax)

cb = matplotlib.colorbar.Colorbar(axc, result)

# Set the colorbar

result.colorbar = cb

py.show()

Hi,

I hope someone can answer this colorbar related question.

I have a plot, to which I am drawing a colorbar. The standard colorbar ranges from the values -1 (blue) over 0 (green) to e.g. 1(red). So far so good.

But now I want to change the colorbar that it shows only the colors between 0 and 1. What I mean is: the colorbar should start at value 0 (with green) and go to 1(red), and leave the original plot unchanged.
I ad some example code below to make it more clear. In the example plot created, only the values between 0 and 1 are interesting and should be shown in the colorbar, but not -1 (blue). But I want the original plot unchanged!

If anyone has an idea that would be great.

Cheers
Alex

import numpy as np
import matplotlib
import pylab as py

f = py.figure()

# create toy image

im = -np.ones((100,100))

for x in range(20,80):
for y in range(20,80):
im[x,y] = random.random()

# create imshow subplot

result = ax.imshow(im)

# Create the colorbar

axc, kw = matplotlib.colorbar.make_axes(ax)

cb = matplotlib.colorbar.Colorbar(axc, result)

# Set the colorbar

result.colorbar = cb

py.show()

2010/6/28 Alexander Dietz <alexanderdietz1@...982...>:

I have a plot, to which I am drawing a colorbar. The standard colorbar
ranges from the values -1 (blue) over 0 (green) to e.g. 1(red). So far so
good.
But now I want to change the colorbar that it shows only the colors between
0 and 1. What I mean is: the colorbar should start at value 0 (with green)
and go to 1(red), and leave the original plot unchanged.

Ah, it wasn't that easy (for me).

Friedrich

help.py (1.31 KB)

Hi Friedrich,

thanks a lot, that was exactly what I was looking for…

Alex

···

On Mon, Jun 28, 2010 at 23:00, Friedrich Romstedt <friedrichromstedt@…287…> wrote:

2010/6/28 Alexander Dietz <alexanderdietz1@…120…982…>:

I have a plot, to which I am drawing a colorbar. The standard colorbar

ranges from the values -1 (blue) over 0 (green) to e.g. 1(red). So far so

good.

But now I want to change the colorbar that it shows only the colors between

0 and 1. What I mean is: the colorbar should start at value 0 (with green)

and go to 1(red), and leave the original plot unchanged.

Ah, it wasn’t that easy (for me).

Friedrich