colorbar to display the 0 in the middle [message #47399] |
Thu, 09 February 2006 17:53  |
vigeesh
Messages: 5 Registered: February 2006
|
Junior Member |
|
|
Hi,
I'm working on a simulation stuff, computationally speaking, its
nothing but generating images for each instant of time.:-)
Each image is accompanied by a colorbar( I use D.Fanning's colorbar
program).
Now my problem is......
At each instant of time, the array that has to be displayed has a
negative minimum value and a positive maximum value. I want my colorbar
to display the 0 in the middle of the bar for all the time instant and
scale the rest according to the min and max value.
There could be a simple solution for this, please help.
Thank you,
Vigeesh.
|
|
|
|
|
|
|
|
Re: colorbar to display the 0 in the middle [message #47484 is a reply to message #47399] |
Fri, 10 February 2006 03:48   |
ph le sager
Messages: 5 Registered: June 2005
|
Junior Member |
|
|
Do you want ALL values or only 0 to be always represented by the same
color?
If you want all, you will need to go with David's answer and always use
the same range in the bar, whatever the data range.
If you want only the 0-level with the same color, you have to be sure
that, for each of your filled contour plot, you have the same color
loaded for the level 0. That means you need to have a contour level
equal to 0, and always assign the same color from the same table to
this 0-level.
Here is a little program that provides a solution. The color in the
middle of the original colortable is assigned to the 0-level, if you
have a 0-level (you need to correctly define RANGE and NFILL -and
that's it-), set the keyword /CENTERED, and use SHIFT to pass to
colorbar. Try the examples, you may change ct to a valid colortable #
(IDL does not come with nice diverging color scheme).
;+
; This program is to get the contour LEVELS and their COLOR INDICES,
; according to the NUMBER of filled contours, and the RANGE to
; consider. The two lattest are the inputs:
;
;
; INPUTS
; nfill: number of contour-colors.
;
; range: this fltarr(2) gives the limits of the
; colorbar. Range[0] is the first contour level.
Range[1]-step
; is the last contour.
;
; INPUT KEYWORD
; center: to center the color table on level=0. This is very
; useful for diverging data. If nfill and range are such
; that there is no levels=0 , then the
; center of the table is aligned with the first value
; above 0.
;
;
; OUTPUT KEYWORDS
; ccolors: set to variable that will hold contour color indices
; levels: set to variable that will hold contour levels
; shift: set to variable that will hold index shift for colorbar
;
;
;
; EFFECT
; A limited number of colors is loaded from the color table, starting
; at index 4 by default (this can be changed with keyword BOTTOM,
; which is passed to LoadCT). You can load any other color in indices
; 0 to 3. Indice 255 (default plotting) may be untouched and free for
; modification, but only if you do not ask for too much color!!
;
; It is possible to center the color table on contour-level=0. This
; is convenient for diverging data (see examples).
; In this case, a SHIFT value is computed for input to COLORBAR
; (from David Fanning) to ensure that
; contour levels and the colorbar match each other.
;
;
; LIMITATION
; Typical usage is shown in examples below. The idea is to choose the
; range and nfill such that we can have integer contours. For example,
; nfill=4 and range=[0,4]. The number of color, nfill, can be
increased,
; but "should" be a multiple of (range[1]-range[0]). See example #3.
;
; The limit on colors number (nfill) is 252 by default [ 256-bottom
; in general case], but it can be less if keyword CENTERED is set,
; because additional colors that are not needed for contours are set.
; A warning message is displayed in case the limit is exceeded.
;
;
; EXAMPLES:
; Add POSITION, and compare the following with a set of data between
[-2.,4.]:
; [ Note that divisions (colorbar keyword, default=6) should be set to
; a small divisor of nfill for lisibility. Here default works ]
;
;
; EXAMPLE (1):
; nfill=6 & range=[-2.,4.] ; inputs
;
; contour_definition, nfill, range , 41, ccolors=cc, levels=lev
; contour, data, c_colors=cc, levels=lev
; colorbar, ncolors=nfill, range=range, bottom=4 ; (default bottom
; here)
;
;
; EXAMPLE (2):
; nfill=6 & range=[-2.,4.] ; inputs
;
; contour_definition, nfill, range, /centered, 41, ccolors=cc, $
; levels=lev, shift=shift
; contour, data, c_colors=cc, levels=lev
; colorbar, ncolors=nfill, range=range, bottom=4+shift
;
;
; EXAMPLE (3):
; nfill=120 & range=[-2.,4.] ; inputs
;
; contour_definition, nfill, range, /centered, 41, ccolors=cc, $
; levels=lev, shift=shift
; contour, data, c_colors=cc, levels=lev
; colorbar, ncolors=nfill, range=range, bottom=4+shift, divisions=3
;
;
; Written by Philippe Le Sager, NOA, 2004
;
;-
pro contour_definition, nfill, range, ct, centered=centered,
bottom=bot, $
ccolors=ccolors, levels=levels, shift=shift
on_error, 2
ncolor=nfill
shift=0
if n_elements(bot) eq 0 then bot=4
; levels
step = (range[1] - range[0]) / nfill
levels = indgen(nfill) * step + range[0]
; case of centered ct for diverging data
if keyword_set(centered) then begin
n_above = total( levels ge 0., /integer)
n_below = total( levels lt 0., /integer)
ncolor = ( n_above > n_below )*2
if n_above gt n_below then shift = (ncolor-nfill)
endif
; check ncolor
if fix(ncolor) gt (256-bot) then $
ok = dialog_message(['TOO MUCH COLORS for Contour...', 'Results
are NOT reliable'])
; load ct
LoadCT, ct, NColors=ncolor, Bottom=bot, /SILENT
ccolors = Indgen(nfill)+bot+shift
END
|
|
|
Re: colorbar to display the 0 in the middle [message #47487 is a reply to message #47399] |
Fri, 10 February 2006 03:12   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Vigeesh Nambiar writes:
> But, I want something like this
> minval = -30
> maxval = +50
>
> i.e my colorbar should look something like this
> ______ 50
> | |
> | |
> | |
> | |
> | |
> | |
> | |- 0
> | |
> | |
> | |
> | |
> | |
> | |
> ------- -30
>
> :-)
>
> Basically, what I want is that the color for the data value 0 should be
> the same for all the output images. That is, if I use a Blue-Red color
> table, then the 0 data value should always be green. The main problem
> is because the minimum and maximum value keeps on changing for
> different arrays. If for the first array the min value is -30 and max
> is 50, for the second array it might be -50 and +75, and so on.
Are you SURE that is what you want? Differential scaling on the positive
and negative sides of your data, and differential scaling on all data
sets!? Wouldn't you want to *compare* the data at some point?
I don't know. It's your data analysis. But this is simply a mapping
problem. Scale negative values into 100 values. Scale positive values
into 100 values. Use a color table that has 200 values. Label it with
YTICKV (since the scale is no longer linear). Just don't include my
name in the acknowledgements, please. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|
RE: colorbar to display the 0 in the middle [message #81506 is a reply to message #47399] |
Sun, 30 September 2012 16:47  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
larsonej writes:
> I have a very simple question that I am having trouble finding an answer to. It is related to this post however. I have a contour map with defined contours in log scale. that go from -4 to 4. I want to make a colorbar to go with it. However, putting the min range = -4 and the max range = 4 and setting /log or /ylog gives me a colorbar that stays positive. Any thoughts? Is there an easy way to do this, or do I have to create a positive and negative colorbar next to each
other?
>
I suppose you could do this:
IDL> cgcolorbar, range=[1./1e4,1e4], /xlog
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
RE: colorbar to display the 0 in the middle [message #81507 is a reply to message #47399] |
Sun, 30 September 2012 16:22  |
larsonej
Messages: 3 Registered: September 2012
|
Junior Member |
|
|
I have a very simple question that I am having trouble finding an answer to. It is related to this post however. I have a contour map with defined contours in log scale. that go from -4 to 4. I want to make a colorbar to go with it. However, putting the min range = -4 and the max range = 4 and setting /log or /ylog gives me a colorbar that stays positive. Any thoughts? Is there an easy way to do this, or do I have to create a positive and negative colorbar next to each other?
Erik
--http://compgroups.net/comp.lang.idl-pvwave/colorbar-to-dis play-the-0-in-the-middle/1103047
|
|
|