comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » colorbar to display the 0 in the middle
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
colorbar to display the 0 in the middle [message #47399] Thu, 09 February 2006 17:53 Go to next message
vigeesh is currently offline  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 #47445 is a reply to message #47399] Sat, 11 February 2006 22:54 Go to previous messageGo to next message
vigeesh is currently offline  vigeesh
Messages: 5
Registered: February 2006
Junior Member
David Fanning wrote:

> After fooling around with this for a few minutes, I
> suspect you may have to write your own colorbar routine.
> Mine uses PLOT to draw annotations, and I don't think you
> can get PLOT to do useful things in non-linear space. :-)

Do you think that I can write a colorbar routine that uses two
different data sets on the same colorbar, one of which is plotted above
0 and the other below zero with this very little knowledge of IDL
programming and data analysis.
Re: colorbar to display the 0 in the middle [message #47476 is a reply to message #47399] Fri, 10 February 2006 08:11 Go to previous messageGo to next message
savoie is currently offline  savoie
Messages: 68
Registered: September 1996
Member
David Fanning <davidf@dfanning.com> writes:

> Vigeesh Nambiar writes:
>
>> As I mentioned I want only 0 to be represented by the same color.
>>
>> Thank you for the program. I'll try it and let you know if it works.
>
> After fooling around with this for a few minutes, I
> suspect you may have to write your own colorbar routine.
> Mine uses PLOT to draw annotations, and I don't think you
> can get PLOT to do useful things in non-linear space. :-)

Wow, you *really* don't want to be attatched to that do you? :)


--
Matthew Savoie - Scientific Programmer
National Snow and Ice Data Center
(303) 735-0785 http://nsidc.org
Re: colorbar to display the 0 in the middle [message #47478 is a reply to message #47399] Fri, 10 February 2006 07:59 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Vigeesh Nambiar writes:

> As I mentioned I want only 0 to be represented by the same color.
>
> Thank you for the program. I'll try it and let you know if it works.

After fooling around with this for a few minutes, I
suspect you may have to write your own colorbar routine.
Mine uses PLOT to draw annotations, and I don't think you
can get PLOT to do useful things in non-linear space. :-)

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 #47480 is a reply to message #47399] Fri, 10 February 2006 07:25 Go to previous messageGo to next message
vigeesh is currently offline  vigeesh
Messages: 5
Registered: February 2006
Junior Member
> Do you want ALL values or only 0 to be always represented by the same
> color?

As I mentioned I want only 0 to be represented by the same color.

Thank you for the program. I'll try it and let you know if it works.
Re: colorbar to display the 0 in the middle [message #47481 is a reply to message #47399] Fri, 10 February 2006 07:22 Go to previous messageGo to next message
vigeesh is currently offline  vigeesh
Messages: 5
Registered: February 2006
Junior Member
> 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!?

Yes, this is exactly what I want

> Wouldn't you want to *compare* the data at some point?

I'm not interested in the whole data.
Just want to see the pattern of 0's in the image, and also to know what
are the maximum and minimum values at each instant and to look at the
gradient on both side(positive and negative, seperately), eventhough
they are not the same.

Anyway, thank you very much

> Just don't include my name in the acknowledgements, please. :-)

Are you sure? :-)

Thank you again.
Re: colorbar to display the 0 in the middle [message #47484 is a reply to message #47399] Fri, 10 February 2006 03:48 Go to previous messageGo to next message
ph le sager is currently offline  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 Go to previous messageGo to next message
David Fanning is currently offline  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 #47542 is a reply to message #47445] Sun, 12 February 2006 07:57 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Vigeesh Nambiar writes:

> Do you think that I can write a colorbar routine that uses two
> different data sets on the same colorbar, one of which is plotted above
> 0 and the other below zero with this very little knowledge of IDL
> programming and data analysis.

I don't think it is a lack of IDL knowledge that is holding you
back right now.

Creating the color bar is trivial. It is scaling the
data properly that is the difficult part. And although
you have convinced me this is what YOU want, I'm just not
sure the rest of the scientific community is ready for
this kind of innovation. :-)

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 Go to previous message
David Fanning is currently offline  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 Go to previous message
larsonej is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: idl workbench: not working properly (plot, buttons and console)
Next Topic: Re: How to change ENVI tmp folder in IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 13:16:33 PDT 2025

Total time taken to generate the page: 2.07954 seconds