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

Home » Public Forums » archive » Adding extra white in middle of colour bar
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
Adding extra white in middle of colour bar [message #85604] Wed, 21 August 2013 03:20 Go to next message
Sir Loin Steak is currently offline  Sir Loin Steak
Messages: 42
Registered: January 2012
Member
Hi all,

I am plotting data that range from negative to positive, so am using a blue-white-red colour bar. However, I would like there to be more white in the middle of the bar.

At the moment I'm using the following clumsy commands to achieve this:

maxv = 10
cgloadct, 13, /brewer, /reverse, ncolors=9, bottom=0, /silent, clip=[0,225]
cgloadct, 16, /brewer, ncolors=9, bottom=12, /silent, clip=[0,225]
clev = scale_vector(findgen(21), -maxv, maxv)
ccol = bindgen(21)
;Make middle levels white
ccol[9:11] = cgcolor('white')

and then:

cgColorbar, ncolors=20, range=[-maxv, maxv]

While this gives me the plot shading I want, the colour bar is incorrect. As I have manually altered the middle values to white, they don't show in the colour bar, which only uses the 18 colours defined by cgloadct.

Is there a simple way around this?

Thanks.
Re: Adding extra white in middle of colour bar [message #85606 is a reply to message #85604] Wed, 21 August 2013 06:03 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
ljs15@fsmail.net writes:

> I am plotting data that range from negative to positive, so am using a blue-white-red colour bar. However, I would like there to be more white in the middle of the bar.
>
> At the moment I'm using the following clumsy commands to achieve this:
>
> maxv = 10
> cgloadct, 13, /brewer, /reverse, ncolors=9, bottom=0, /silent, clip=[0,225]
> cgloadct, 16, /brewer, ncolors=9, bottom=12, /silent, clip=[0,225]
> clev = scale_vector(findgen(21), -maxv, maxv)
> ccol = bindgen(21)
> ;Make middle levels white
> ccol[9:11] = cgcolor('white')
>
> and then:
>
> cgColorbar, ncolors=20, range=[-maxv, maxv]
>
> While this gives me the plot shading I want, the colour bar is incorrect. As I have manually altered the middle values to white, they don't show in the colour bar, which only uses the 18 colours defined by cgloadct.
>
> Is there a simple way around this?

I think the simplest way around it is this:

cgLoadCT, 22, /Brewer, /Reverse, NColors=20
cgColorBar, NColors=20, range=[-10,10]

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Adding extra white in middle of colour bar [message #85607 is a reply to message #85606] Wed, 21 August 2013 06:33 Go to previous messageGo to next message
Sir Loin Steak is currently offline  Sir Loin Steak
Messages: 42
Registered: January 2012
Member
On Wednesday, 21 August 2013 14:03:57 UTC+1, David Fanning wrote:
> ljs15@fsmail.net writes:
>
>
>
>> I am plotting data that range from negative to positive, so am using a blue-white-red colour bar. However, I would like there to be more white in the middle of the bar.
>
>>
>
>> At the moment I'm using the following clumsy commands to achieve this:
>
>>
>
>> maxv = 10
>
>> cgloadct, 13, /brewer, /reverse, ncolors=9, bottom=0, /silent, clip=[0,225]
>
>> cgloadct, 16, /brewer, ncolors=9, bottom=12, /silent, clip=[0,225]
>
>> clev = scale_vector(findgen(21), -maxv, maxv)
>
>> ccol = bindgen(21)
>
>> ;Make middle levels white
>
>> ccol[9:11] = cgcolor('white')
>
>>
>
>> and then:
>
>>
>
>> cgColorbar, ncolors=20, range=[-maxv, maxv]
>
>>
>
>> While this gives me the plot shading I want, the colour bar is incorrect. As I have manually altered the middle values to white, they don't show in the colour bar, which only uses the 18 colours defined by cgloadct.
>
>>
>
>> Is there a simple way around this?
>
>
>
> I think the simplest way around it is this:
>
>
>
> cgLoadCT, 22, /Brewer, /Reverse, NColors=20
>
> cgColorBar, NColors=20, range=[-10,10]
>
>
>
> Cheers,
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")

Hi David,

That's the method I originally used, but that means the white colour is only being given to the middle contour range.

What I want (for example) is eight contours -10,-9,...,-2 to be shades of blue, and eight contours 2,3,...,10 to be shades of red, and the contours between -2 and +2 to be white.

Not sure if this is possible without having to manually make a colour table and load it with tvlct.
Re: Adding extra white in middle of colour bar [message #85608 is a reply to message #85607] Wed, 21 August 2013 07:04 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
ljs15@fsmail.net writes:

> That's the method I originally used, but that means the white colour is only being given to the middle contour range.
>
> What I want (for example) is eight contours -10,-9,...,-2 to be shades of blue, and eight contours 2,3,...,10 to be shades of red, and the contours between -2 and +2 to be white.
>
> Not sure if this is possible without having to manually make a colour table and load it with tvlct.

If the right color table doesn't exist, you have to create it. No
question about that. :-)

cgLoadCT, 22, /Brewer, /Reverse, NColors=21
TVLCT, cgColor(Replicate('white',3), /Triple), 9
cgColorbar, NColors=21, Range=[-10,10], XTicks=2, XMinor=0

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Adding extra white in middle of colour bar [message #85613 is a reply to message #85608] Wed, 21 August 2013 12:52 Go to previous messageGo to next message
Sir Loin Steak is currently offline  Sir Loin Steak
Messages: 42
Registered: January 2012
Member
On Wednesday, 21 August 2013 15:04:46 UTC+1, David Fanning wrote:
> ljs15@fsmail.net writes:
>
>
>
>> That's the method I originally used, but that means the white colour is only being given to the middle contour range.
>
>>
>
>> What I want (for example) is eight contours -10,-9,...,-2 to be shades of blue, and eight contours 2,3,...,10 to be shades of red, and the contours between -2 and +2 to be white.
>
>>
>
>> Not sure if this is possible without having to manually make a colour table and load it with tvlct.
>
>
>
> If the right color table doesn't exist, you have to create it. No
>
> question about that. :-)
>
>
>
> cgLoadCT, 22, /Brewer, /Reverse, NColors=21
>
> TVLCT, cgColor(Replicate('white',3), /Triple), 9
>
> cgColorbar, NColors=21, Range=[-10,10], XTicks=2, XMinor=0
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")


Thanks David, that's very helpful.

But this does bring me on to something else I've been wondering about regarding contours and fill colours (sorry for all the questions!).

Say I had data and wanted to contour it from -10 to +10 using a blue-white-red colour scale. I would normally do:

ncont = 21
cgloadct, 22, /brewer, /reverse, ncolors=ncont, /silent
clev = scale_vector(findgen(ncont), -maxval, maxval)
ccol = bindgen(ncont)

Then contour it using levels=clev, c_colors=ccol.

However, I actually want [-10,-9] to be one colour, [-9,-8] to be another colour etc. So I actually need 20 fill colours not 21.

If I select ncont=20 then my levels do not come out as integer values, but using ncont=21 means the colour bar is not divided neatly in two, with red colours > 0 and blue colours < 0.

Am I misunderstanding how IDL fills in the contours? Is there a way around this problem? I assume that if I set the levels to [-1,0,1] and tell IDL to fill the contour plot, then it fills [-1,0],[0,1],[1,1+].

Thanks again for the help.
Re: Adding extra white in middle of colour bar [message #85615 is a reply to message #85613] Wed, 21 August 2013 17:13 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
ljs15@fsmail.net writes:

> But this does bring me on to something else I've been wondering about regarding contours and fill colours (sorry for all the questions!).
>
> Say I had data and wanted to contour it from -10 to +10 using a blue-white-red colour scale. I would normally do:
>
> ncont = 21
> cgloadct, 22, /brewer, /reverse, ncolors=ncont, /silent
> clev = scale_vector(findgen(ncont), -maxval, maxval)
> ccol = bindgen(ncont)
>
> Then contour it using levels=clev, c_colors=ccol.
>
> However, I actually want [-10,-9] to be one colour, [-9,-8] to be another colour etc. So I actually need 20 fill colours not 21.
>
> If I select ncont=20 then my levels do not come out as integer values, but using ncont=21 means the colour bar is not divided neatly in two, with red colours > 0 and blue colours < 0.
>
> Am I misunderstanding how IDL fills in the contours? Is there a way around this problem? I assume that if I set the levels to [-1,0,1] and tell IDL to fill the contour plot, then it fills [-1,0],[0,1],[1,1+].

Well, you can test this easily enough.

data = cgScaleVector(Dist(51), -10, 10)
pos = [0.125, 0.125, 0.925, 0.8]
cgColorFill, Position=pos, Color='charcoal'
cgLoadCT, 22, /Brewer, /Reverse, NColors=3, Bottom=1
cgContour, data, Levels=[-1, 0, 1], C_Colors=Bindgen(3)+1B, $
Position=pos, /NoErase, /Outline, /Fill

So, you are exactly right. You see from this plot that anything less
than -1 was filled with the background color (charcoal) and that
anything greater than 1 was filled with the red color.

The color bar for such a plot would look like this:

cgcolorbar, ncolors = 2, oob_low='charcoal', oob_high=3, $
range=[-1,1], bottom=1, xticks=3, xminor=0

If you are going to use out-of-bounds colors, then the number of colors
in your color bar is always going to be one less than the number of
levels in your contour plot.

If you are NOT going to use out-of-bounds colors (this is what I think
you are asking about), then the number of contour levels you need is
always one more than the number of colors you want to use. Think of how
many vertical lines you have to draw in a color bar to separate or
block-off X number of colors. For three colors, for example, you have to
draw a vertical line on the left, where the color starts, one between
the first and second color, one between the second and third color, and
one to show where the third color ends.

Consider this:

cgLoadCT, 0
TVLCT, cgColor(['blu6','grn6','red6'], /Triple), 1
levels = [-1,0,1,2]
cgContour, data, Levels=levels, C_Colors=Bindgen(3)+1B, $
Position=pos, /NoErase, /Outline, /Fill

Yikes! We have blue, green, and red contours, but why is everything
greater than 2 the same color as the -1 to 0 level? Well, because we
have the "greater than 2" contour to draw, and the colors recycle. In
this case, the fourth color is the same as the first, the fifth the same
as the second, etc. So, to get what we want we have to load another
color and tell the contour plot to load it. Let's make the fourth color
the same as the background color, like this:

cgLoadCT, 0
TVLCT, cgColor(['blu6','grn6','red6'], /Triple), 1
TVLCT, cgColor('white', /Triple), 4
levels = [-1,0,1,2]
cgContour, data, Levels=levels, C_Colors=Bindgen(4)+1B, $
Position=pos, /NoErase, /Outline, /Fill

But, now, what about the color bar? It uses three colors, and the range
is -1 to 2.

cgcolorbar, ncolors = 3, range=[-1,2], bottom=1, xticks=3, xminor=0

In other words, it's pretty damm confusing. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Adding extra white in middle of colour bar [message #85619 is a reply to message #85615] Thu, 22 August 2013 05:57 Go to previous messageGo to next message
Sir Loin Steak is currently offline  Sir Loin Steak
Messages: 42
Registered: January 2012
Member
On Thursday, 22 August 2013 01:13:41 UTC+1, David Fanning wrote:
> ljs15@fsmail.net writes:
>
>
>
>> But this does bring me on to something else I've been wondering about regarding contours and fill colours (sorry for all the questions!).
>
>>
>
>> Say I had data and wanted to contour it from -10 to +10 using a blue-white-red colour scale. I would normally do:
>
>>
>
>> ncont = 21
>
>> cgloadct, 22, /brewer, /reverse, ncolors=ncont, /silent
>
>> clev = scale_vector(findgen(ncont), -maxval, maxval)
>
>> ccol = bindgen(ncont)
>
>>
>
>> Then contour it using levels=clev, c_colors=ccol.
>
>>
>
>> However, I actually want [-10,-9] to be one colour, [-9,-8] to be another colour etc. So I actually need 20 fill colours not 21.
>
>>
>
>> If I select ncont=20 then my levels do not come out as integer values, but using ncont=21 means the colour bar is not divided neatly in two, with red colours > 0 and blue colours < 0.
>
>>
>
>> Am I misunderstanding how IDL fills in the contours? Is there a way around this problem? I assume that if I set the levels to [-1,0,1] and tell IDL to fill the contour plot, then it fills [-1,0],[0,1],[1,1+].
>
>
>
> Well, you can test this easily enough.
>
>
>
> data = cgScaleVector(Dist(51), -10, 10)
>
> pos = [0.125, 0.125, 0.925, 0.8]
>
> cgColorFill, Position=pos, Color='charcoal'
>
> cgLoadCT, 22, /Brewer, /Reverse, NColors=3, Bottom=1
>
> cgContour, data, Levels=[-1, 0, 1], C_Colors=Bindgen(3)+1B, $
>
> Position=pos, /NoErase, /Outline, /Fill
>
>
>
> So, you are exactly right. You see from this plot that anything less
>
> than -1 was filled with the background color (charcoal) and that
>
> anything greater than 1 was filled with the red color.
>
>
>
> The color bar for such a plot would look like this:
>
>
>
> cgcolorbar, ncolors = 2, oob_low='charcoal', oob_high=3, $
>
> range=[-1,1], bottom=1, xticks=3, xminor=0
>
>
>
> If you are going to use out-of-bounds colors, then the number of colors
>
> in your color bar is always going to be one less than the number of
>
> levels in your contour plot.
>
>
>
> If you are NOT going to use out-of-bounds colors (this is what I think
>
> you are asking about), then the number of contour levels you need is
>
> always one more than the number of colors you want to use. Think of how
>
> many vertical lines you have to draw in a color bar to separate or
>
> block-off X number of colors. For three colors, for example, you have to
>
> draw a vertical line on the left, where the color starts, one between
>
> the first and second color, one between the second and third color, and
>
> one to show where the third color ends.
>
>
>
> Consider this:
>
>
>
> cgLoadCT, 0
>
> TVLCT, cgColor(['blu6','grn6','red6'], /Triple), 1
>
> levels = [-1,0,1,2]
>
> cgContour, data, Levels=levels, C_Colors=Bindgen(3)+1B, $
>
> Position=pos, /NoErase, /Outline, /Fill
>
>
>
> Yikes! We have blue, green, and red contours, but why is everything
>
> greater than 2 the same color as the -1 to 0 level? Well, because we
>
> have the "greater than 2" contour to draw, and the colors recycle. In
>
> this case, the fourth color is the same as the first, the fifth the same
>
> as the second, etc. So, to get what we want we have to load another
>
> color and tell the contour plot to load it. Let's make the fourth color
>
> the same as the background color, like this:
>
>
>
> cgLoadCT, 0
>
> TVLCT, cgColor(['blu6','grn6','red6'], /Triple), 1
>
> TVLCT, cgColor('white', /Triple), 4
>
> levels = [-1,0,1,2]
>
> cgContour, data, Levels=levels, C_Colors=Bindgen(4)+1B, $
>
> Position=pos, /NoErase, /Outline, /Fill
>
>
>
> But, now, what about the color bar? It uses three colors, and the range
>
> is -1 to 2.
>
>
>
> cgcolorbar, ncolors = 3, range=[-1,2], bottom=1, xticks=3, xminor=0
>
>
>
> In other words, it's pretty damm confusing. :-)
>
>
>
> Cheers,
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")


Brilliant! It actually makes sense now.

Thanks very much for that detailed reply. Sometimes I wonder how the IDL community would do without you!
Re: Adding extra white in middle of colour bar [message #85621 is a reply to message #85619] Thu, 22 August 2013 06:15 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
ljs15@fsmail.net writes:

> Brilliant! It actually makes sense now.
>
> Thanks very much for that detailed reply. Sometimes I wonder how the IDL community would do without you!

My guess is Philip will take over for the Dread Pirate Roberts and the
world will go on pretty much as it always has. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: spawn not working
Next Topic: Navigating AVIRIS Images

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

Current Time: Wed Oct 08 15:06:01 PDT 2025

Total time taken to generate the page: 0.00863 seconds