## matplotlib-users

 [Matplotlib-users] colorbar rescaling From: Alexander Dietz - 2010-06-28 18:43:38 Attachments: Message as HTML ```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 ax = f.add_subplot(111) 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() ```
 [Matplotlib-users] colorbar rescaling From: Alexander Dietz - 2010-06-28 18:54:06 Attachments: Message as HTML ```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 ax = f.add_subplot(111) 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() ```
 Re: [Matplotlib-users] colorbar rescaling From: Friedrich Romstedt - 2010-06-28 21:00:07 Attachments: help.py ```2010/6/28 Alexander Dietz : > 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 ```
 Re: [Matplotlib-users] colorbar rescaling From: Alexander Dietz - 2010-06-29 10:37:01 Attachments: Message as HTML ```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@...> wrote: > 2010/6/28 Alexander Dietz : > > 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 > ```