1

Possible Duplicate:
Set Colorbar Range in matplotlib
Defining the midpoint of a colormap in matplotlib

When you have a colorbar in python (pyplot), it is possible to have an asymmetrical range of values

e.g. -4 -> 12

but still somehow have the white / neutral colour (usually the mid-point of the colorbar) at 0 - even though 0 is tending toward the bottom of the colorbar in this example?

Thank you.

Community
  • 1
  • 1
user1551817
  • 6,693
  • 22
  • 72
  • 109
  • 1
    you don't want to adjust only the limits, but to get a colormap where you can somehow specify the limits and the central point? – moooeeeep Jan 17 '13 at 20:03

1 Answers1

1

There are several ways to do this.

It sounds like you might want to use vmin and vmax to force a range for the colorbar. That would look like:

imshow(data, vmin=-12, vmax=12)

This will allow your data to have the range -4 to 12, and the center of colorbar will be at zero, but the colorbar will span -12 to 12. This is useful, for example, in comparison plots between two data sets with slightly different ranges, as in this SO question.

On the other hand, if you want your colorbar to have a colormap specifically derived for you data range, with a particular colors corresponding to a particular values, etc, than you'll need to make your own colormap. It's a hassle, but not too hard. Here's an example.

Community
  • 1
  • 1
tom10
  • 67,082
  • 10
  • 127
  • 137