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

Home » Public Forums » archive » Plotting with colorbar
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
Plotting with colorbar [message #87213] Thu, 16 January 2014 07:41 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

I have a data matrix with 99 columns and 86400 rows (each row represents time in seconds). The whole of the data matrix is arranged with only 5 numbers = [-9, 1, 2, 3, 4]. I wanted to make a color bar with 4 colors = ['DARK RED','RED','SKY BLUE', 'BLUE'] representing numbers [1, 2, 3, 4] respectively and -9 represents a missing value (assigned 'WHITE' color)

Below are my lines in the code for synthetic data:

time=LINDGEN(86400) ; in seconds

tmp_data=REPMAT([-9,1,2,3,4],20,86400)
data=tmp_data[0:98,*]

missingIndices=WHERE(data EQ -9, missingCount)
IF missingCount GT 0 THEN data[missingIndices]=0

img=BytScl(data,MIN=0,MAX=4,/NAN)

TVLCT, cgColor('WHITE',/Triple),0 ; Background color
TVLCT, cgColor(['DARK RED','RED','SKY BLUE','BLUE'],/Triple),1

???
???

Now my problem is ... I want X-axis with time, Y-axis with data column indices (i.e., indgen(99)) where I wanted to place colored dots (basing on the colorbar) for each of the data point column wise for all the time points. Can anyone suggest me how shall I proceed after the above steps in simplest way?

Thanks in advance
Re: Plotting with colorbar [message #87214 is a reply to message #87213] Thu, 16 January 2014 08:37 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

> I have a data matrix with 99 columns and 86400 rows (each row
represents time in seconds). The whole of the data matrix is arranged
with only 5 numbers = [-9, 1, 2, 3, 4]. I wanted to make a color bar
with 4 colors = ['DARK RED','RED','SKY BLUE', 'BLUE'] representing
numbers [1, 2, 3, 4] respectively and -9 represents a missing value
(assigned 'WHITE' color)
>
> Below are my lines in the code for synthetic data:
>
> time=LINDGEN(86400) ; in seconds
>
> tmp_data=REPMAT([-9,1,2,3,4],20,86400)
> data=tmp_data[0:98,*]
>
> missingIndices=WHERE(data EQ -9, missingCount)
> IF missingCount GT 0 THEN data[missingIndices]=0

The following command is unnecessary.

> img=BytScl(data,MIN=0,MAX=4,/NAN)

It probably doesn't hurt anything, but you could do just as well with
this command:

img = Byte(data)

> TVLCT, cgColor('WHITE',/Triple),0 ; Background color
> TVLCT, cgColor(['DARK RED','RED','SKY BLUE','BLUE'],/Triple),1
>
> ???
> ???
>
> Now my problem is ... I want X-axis with time, Y-axis with data column indices (i.e., indgen(99)) where I wanted to place colored dots (basing on the colorbar) for each of the data point column wise for all the time points. Can anyone suggest me how shall I proceed after the above steps in simplest way?

You don't want colored dots. Putting them on your plot will take weeks,
if not longer. And, unless you are making your plot the size of a
building, you wouldn't see individual dots anyway. :-)

Try this:

time=LINDGEN(86400) ; in seconds
tmp_data=REPMAT([-9,1,2,3,4],20,86400)
data=tmp_data[0:98,*]
missingIndices=WHERE(data EQ -9, missingCount)
IF missingCount GT 0 THEN data[missingIndices]=0
img=Byte(data)
TVLCT, cgColor('WHITE',/Triple),0 ; Background color
TVLCT, cgColor(['DARK RED','RED','SKY BLUE','BLUE'],/Triple),1
cgimage, Transpose(data), /axes, axkeyword={xtitle:'Time'}
END

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: Plotting with colorbar [message #87225 is a reply to message #87214] Thu, 16 January 2014 13:24 Go to previous messageGo to next message
fischertc13 is currently offline  fischertc13
Messages: 4
Registered: October 2012
Junior Member
>
> Try this:
>
>
>
> time=LINDGEN(86400) ; in seconds
>
> tmp_data=REPMAT([-9,1,2,3,4],20,86400)
>
> data=tmp_data[0:98,*]
>
> missingIndices=WHERE(data EQ -9, missingCount)
>
> IF missingCount GT 0 THEN data[missingIndices]=0
>
> img=Byte(data)
>
> TVLCT, cgColor('WHITE',/Triple),0 ; Background color
>
> TVLCT, cgColor(['DARK RED','RED','SKY BLUE','BLUE'],/Triple),1
>
> cgimage, Transpose(data), /axes, axkeyword={xtitle:'Time'}
>
> END
>
>
>
> 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 all,

I have a similar question where I have populated a 2D field with velocity measurements that are assigned a rainbow of colors and want array points that do not have a value to be whited out (or preferably not shown at all). I assign all points without a velocity a NaN value, but that just ends up assigning these points the 0 value in the Rainbow color table I am using.

I can get the valueless array points to be white by instead assigning them some high velocity (i.e. 999999) in the Rainbow+White color table, but I when I try to plot the image as a postscript it instead uses the 254 value right before white which is instead red. Additionally, this puts a white bar at the top of my color bar which is a bit annoying.

Here is what I'm using right now:


i = WHERE(field EQ 0.000, count)
IF (count GT 0) THEN array1[i] = !VALUES.F_NAN

set_plot, 'ps'
!p.font=0
device, filename='vel_center.eps',bits_per_pixel=8,/portrait,/inches , $
xsize = 7.2, ysize = 6.,/encapsulated,/color,xoffset=1.0,yoffset=1.0

!p.noerase=1

loadct,39 ;rainbow

tvim,array1,range=[-300,300],POSITION=[.08,.05,.83,.95],/noa xis

fsc_contour,image,levels=levels,/overplot,color='black',labe l=0

loadct,0 ; b & w

loadct,39 ;rainbow

FSC_COLORBAR, POSITION=[0.83,0.05,0.88,0.95], Divisions=4, Minor=5, Format='(F5.0)', Range=[-300, 300],title='Velocity (km/s)',/vertical,/right

device, /close
set_plot, 'x'
loadct,0 ; b & w

Any comments are appreciated!

Cheers,
Travis
Re: Plotting with colorbar [message #87228 is a reply to message #87225] Fri, 17 January 2014 04:11 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
fischertc13@gmail.com writes:

> I have a similar question where I have populated a 2D field with velocity measurements that are assigned a rainbow of colors and want array points that do not have a value to be whited out (or preferably not shown at all). I assign all points without a velocity a NaN value, but that just ends up assigning these points the 0 value in the Rainbow color table I am using.
>
> I can get the valueless array points to be white by instead assigning them some high velocity (i.e. 999999) in the Rainbow+White color table, but I when I try to plot the image as a postscript it instead uses the 254 value right before white which is instead red. Additionally, this puts a white bar at the top of my color bar which is a bit annoying.
>
> Here is what I'm using right now:
>
>
> i = WHERE(field EQ 0.000, count)
> IF (count GT 0) THEN array1[i] = !VALUES.F_NAN
>
> set_plot, 'ps'
> !p.font=0
> device, filename='vel_center.eps',bits_per_pixel=8,/portrait,/inches , $
> xsize = 7.2, ysize = 6.,/encapsulated,/color,xoffset=1.0,yoffset=1.0
>
> !p.noerase=1
>
> loadct,39 ;rainbow
>
> tvim,array1,range=[-300,300],POSITION=[.08,.05,.83,.95],/noa xis
>
> fsc_contour,image,levels=levels,/overplot,color='black',labe l=0
>
> loadct,0 ; b & w
>
> loadct,39 ;rainbow
>
> FSC_COLORBAR, POSITION=[0.83,0.05,0.88,0.95], Divisions=4, Minor=5, Format='(F5.0)', Range=[-300, 300],title='Velocity (km/s)',/vertical,/right
>
> device, /close
> set_plot, 'x'
> loadct,0 ; b & w
>
> Any comments are appreciated!

I would do a couple of things. First, I would update your Coyote
Library. It appears to be about five years out of date. Then I would
investigate the transparent properties of cgImage, specifically the
MISSING keyword:

http://www.idlcoyote.com/idldoc/cg/cgimage.html

What you want to do is pretty easy:

http://www.idlcoyote.com/cg_tips/transimage.php

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: Plotting with colorbar [message #87237 is a reply to message #87225] Sun, 19 January 2014 11:18 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
fischertc13@gmail.com writes:

>
>>
>> Try this:
>>
>>
>>
>> time=LINDGEN(86400) ; in seconds
>>
>> tmp_data=REPMAT([-9,1,2,3,4],20,86400)
>>
>> data=tmp_data[0:98,*]
>>
>> missingIndices=WHERE(data EQ -9, missingCount)
>>
>> IF missingCount GT 0 THEN data[missingIndices]=0
>>
>> img=Byte(data)
>>
>> TVLCT, cgColor('WHITE',/Triple),0 ; Background color
>>
>> TVLCT, cgColor(['DARK RED','RED','SKY BLUE','BLUE'],/Triple),1
>>
>> cgimage, Transpose(data), /axes, axkeyword={xtitle:'Time'}
>>
>> END
>>
>>
>>
>> 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 all,
>
> I have a similar question where I have populated a 2D field with velocity measurements that are assigned a rainbow of colors and want array points that do not have a value to be whited out (or preferably not shown at all). I assign all points without a velocity a NaN value, but that just ends up assigning these points the 0 value in the Rainbow color table I am using.
>
> I can get the valueless array points to be white by instead assigning them some high velocity (i.e. 999999) in the Rainbow+White color table, but I when I try to plot the image as a postscript it instead uses the 254 value right before white which is instead red. Additionally, this puts a white bar at the top of my color bar which is a bit annoying.
>
> Here is what I'm using right now:
>
>
> i = WHERE(field EQ 0.000, count)
> IF (count GT 0) THEN array1[i] = !VALUES.F_NAN
>
> set_plot, 'ps'
> !p.font=0
> device, filename='vel_center.eps',bits_per_pixel=8,/portrait,/inches , $
> xsize = 7.2, ysize = 6.,/encapsulated,/color,xoffset=1.0,yoffset=1.0
>
> !p.noerase=1
>
> loadct,39 ;rainbow
>
> tvim,array1,range=[-300,300],POSITION=[.08,.05,.83,.95],/noa xis
>
> fsc_contour,image,levels=levels,/overplot,color='black',labe l=0
>
> loadct,0 ; b & w
>
> loadct,39 ;rainbow
>
> FSC_COLORBAR, POSITION=[0.83,0.05,0.88,0.95], Divisions=4, Minor=5, Format='(F5.0)', Range=[-300, 300],title='Velocity (km/s)',/vertical,/right
>
> device, /close
> set_plot, 'x'
> loadct,0 ; b & w
>
> Any comments are appreciated!

I'm just about to get on a plane, so I can elaborate, but I would update
your Coyote Library (it is about 5 years out of date) and then
investigate the transparency keywords available in cgImage. This will be
simple to do. You can find entire articles written about it on my web
page. :-)

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: Maps - ellipsoids in map_set ('scale on the central meridian')
Next Topic: averaging w.r.t time resolution

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

Current Time: Wed Oct 08 15:48:58 PDT 2025

Total time taken to generate the page: 0.00511 seconds