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

Home » Public Forums » archive » What exactly does the command "strech" do to the colormap?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: What exactly does the command "strech" do to the colormap? [message #66050 is a reply to message #66010] Mon, 13 April 2009 05:41 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
ICBM0926 writes:

> Dear David
> Thanks for your reply. What I am trying to do is to write a procedure
> which is a paart of my analysis procedures which is used to analysis
> simulation dumped data in HDF5 format.
> I try to make it user friendly, so user only needs to call these
> procedures with certain parameters and then they get what they want.
> One of the features is that user can set "dynamical range" of their
> colored contour plot.
> I've written a procedures to creat colored contour. Before the
> fielddata ("field" array) is sent into this procedures, it goes throug
> following loop to make sure the data within the dynamical range.
>
> if fieldarrsize[0] eq 2 then begin
> if n_elements(dyrange) ne 0 then begin
> for j=0 ,nx1-1L do begin
> for i=0 ,nx0-1L do begin
> if field(i,j) GT dyrange[1] then begin
> field(i,j)=dyrange[1]
> endif else if field(i,j) LT dyrange[0] then begin
> field(i,j)=dyrange[0]
> endif
> endfor
> endfor
> endif
> endif
>
> After this loop, the fielddata is sent into "my_vp_fieldtvscl.pro".
> That procedure is used to creat colored contour. What I am trying to
> accomplish through "strech" is to make sure the consistency between
> colorbar and colored contour of fielddata. The following code is
> "my_vp_fieldtvscl.pro".
> ==================================
> ;********************************************************
> ;T.H.Hshieh IAMS
> ;This program is to plot field data with TVSCL.
> ;20090205
> ;********************************************************
> pro my_vp_fieldtvscl,fielddata, x0axis, x1axis, x0_label=x0_label,
> x1_label=x1_label, ct=ct, invct=invct, cbby_title=cbby_title,
> title_str=title_str, psoutfilename=psoutfilename, $
> cbby_ticknum=cbby_ticknum, dyrange=dyrange, time=time
>
> if n_elements(x0_label) eq 0 then x0_label='x0'
> if n_elements(x1_label) eq 0 then x1_label='x1'
> if n_elements(cbby_title) eq 0 then cbby_title='colorbar'
> if n_elements(dyrange) eq 0 then begin
> cbrange=dblarr(2)
> cbrange(0)=min(fielddata)
> cbrange(1)=max(fielddata)
> endif else begin
> cbrange=dyrange
> endelse
> if n_elements(cbby_ticknum) eq 0 then begin
> cbby_ticknum=4
> endif
> print,"cbby_ticknum",cbby_ticknum
> !P.TITLE = title_str
> ;================plot parameter========
> x0_charsize=1.2
> x1_charsize=1.2
> p_charthick=6
> line_thick=6
> x0_ticklen=0.06
> x1_ticklen=0.06
> ict=ct
> ist_low=0
> ist_high=255
> ;**************position**************************
> x0_size=30
> x1_size=30/1.6803
> x0_offset=1
> x1_offset=5
> ;******************colorcon position**************
> px1=0.69
> py1=0.8
> px0=0.2
> py0=py1-(4.8*(px1-px0)*1.6803)/7
> print,'py0=',py0
> ;******************color bar position**************
> cbx0=0.70
> cby0=py0
> cbx1=0.74
> cby1=py1
> ;*******************Other parameters*****************
> !P.Multi=[0,1,1]
> !x.style=1
> !y.style=1
> !x.charsize=x0_charsize
> !y.charsize=x1_charsize
> !p.charthick = p_charthick
> !x.thick=line_thick
> !y.thick=line_thick
> !p.font=0
> ;===========max & min==============
> x0_min=min(x0axis)
> x0_max=max(x0axis)
> x0_ticks=5.
> x0_minor=5.
> x0_interval=(max(x0axis)-min(x0axis))/x0_ticks
> x1_min=min(x1axis)
> x1_max=max(x1axis)
> x1_ticks=5.
> x1_minor=5.
> colorbar_ticklen=0.2
> colorbar_minor=5
> ;===================================
> ;title
> cbby_title=cbby_title
> colorbar_max=cbrange(1)
> colorbar_min=cbrange(0)
>
> ;-------------setting color bar array-----------------
> cb_arr=dblarr(1,256)
> dcb=(colorbar_max-colorbar_min)/(256.-1.)
> cb_arr(0,0)=colorbar_min
> for i=1,256-1 do begin
> cb_arr(0,i)=cb_arr(0,i-1)+dcb
> endfor
> ; rendering to screen is done. here we render to ps file
> set_plot, 'ps'
> device,/color,SET_FONT='Helvetica'
> device, filename=psoutfilename, /color,
> bits_per_pixel=8 ,SET_FONT='Helvetica' $
> ,xsize=x0_size, ysize=x1_size, xoffset=x0_offset, yoffset=x1_offset,/
> portrait
> !p.charsize=1.6
> ;plot data
> plot , [x0_min,x0_max],[x1_min,x1_max], /nodata, /noerase $
> , position=[px0,py0,px1,py1] $
> , xstyle=5, ystyle=5,title=''
> LoadCT, ict
> ;*******************************************************
> ;in order to prevent from the incorrect color bar label.
> ;The color table must be redefined by "strech".
> ;*******************************************************
> if (max(fielddata) LT cbrange(1)) or (min(fielddata) GT cbrange(0))
> then begin
> data_ist_high=ist_high+(cbrange(1)-max(fielddata))/(max(fiel ddata)-min
> (fielddata))*double(n_elements(cb_arr))
> data_ist_high=round(data_ist_high)
> print,'data_ist_high=',data_ist_high
> data_ist_low=ist_low-(min(fielddata)-cbrange(0))/(max(fieldd ata)-min
> (fielddata))*double(n_elements(cb_arr))
> data_ist_low=round(data_ist_low)
> print,'data_ist_low=', data_ist_low
> endif else begin
> data_ist_high=ist_high
> data_ist_low=ist_low
> endelse
> stretch ,data_ist_low,data_ist_high
> if n_elements(invct) ne 0 then stretch ,data_ist_high,data_ist_low
> xsize=(px1-px0)* !D.X_VSize
> ysize=(py1-py0)* !D.Y_VSize
> xstart=px0* !D.X_VSize
> ystart=py0* !D.Y_VSize
> TVScl, fielddata, xstart,ystart,XSize=xsize,YSize=ysize
> LoadCT,0 ; reset color table
> stretch, 0,255
> yticksv=dindgen(x1_ticks)*(max(x1axis)-min(x1axis))/x1_ticks + min
> (x1axis)
> ;plot x0 axis
>
> axis, x0_min, x1_min, xaxis=0 $
> , xtitle=x0_label $
> , xticks=x0_ticks, xminor=x0_minor, ticklen=x0_ticklen
> ;plot x1 axis
> axis, x0_min, x1_min, yaxis=0 $
> , ytitle=x1_label $
> , yticks=x1_ticks $
> , yminor=x1_minor $
> , ticklen=x1_ticklen
> if n_elements(time) ne 0 then begin
> string_temp = 'T='+string(time)+'(s)'
> string_temp = strcompress(string_temp,/remove_all)
> XYOUTS, 0.1,0.9, string_temp, CHARSIZE=1.5,CHARTHICK=3, /normal
> endif
> ;--------------------plot remainings--------------------
>
> ;plot color bar
[color=blue]> plot ,[0.,1.],[colorbar_min,colorbar_max], /nodata, /noerase $[/color]
> ,position=[cbx0,cby0,cbx1,cby1] $
> , xstyle=5,ystyle=5,title=''
>
> LoadCT, ict
> stretch ,ist_low,ist_high
> if n_elements(invct) ne 0 then stretch ,ist_high,ist_low
> print,'data_ist_low',data_ist_low
> print,'data_ist_high',data_ist_high
>
> xsize=(cbx1-cbx0)* !D.X_VSize
> ysize=(cby1-cby0)* !D.Y_VSize
> xstart=cbx0* !D.X_VSize
> ystart=cby0* !D.Y_VSize
>
> TVSCL , cb_arr,xstart,ystart,XSize=xsize,YSize=ysize
>
> LoadCT, 0
> stretch ,0,255
> ;---------------------plot y axis---------------------
> axis,1.,colorbar_min,yaxis=1 $
> ,ticklen=colorbar_ticklen $
> ,ytitle=cbby_title $
> ,yticks=cbby_ticknum $
> ,yminor=colorbar_minor
>
> ;-----------------------------------------------------
>
> ; here rendering to file is done. set back to screen defaults
> device, /close
> print,'Outputfile=', psoutfilename ,' done!'
> end
> ===============================================
>
> Clearly in the above code, I use "dyrange" (Dynamical range, a 2-
> element factor contsinas(min,max) of desired data value range. ) as
> colorbar label. But the fielddata can be min(fieldata) > dyrange(0) or
> max( fielddata) < dyrange(1).
> I use "stretch" to make sure the consistency between colorbar and
> fielddata colored contour. The output plots seems right. I just tried
> to make sure what i am doing is right.
>
> The colored contour in ypur web page is plottedby contour command. I
> remember that that command can only be used for levels < 60. That's
> why I use TVSCL instead of contour.
>
> Thanks for your refernces anyway

My point was only that all of this could be done (and in
about half a dozen lines of code) without the use of TVSCL
and STRETCH, which will tend to confuse you about color.
But, maybe this is the least of your problems. Looks like
you have things well in hand. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Previous Topic: Fourier analysis of the Data with some gaps
Next Topic: Re: Write graphics to two devices simultaneously?

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

Current Time: Sun Oct 12 13:09:00 PDT 2025

Total time taken to generate the page: 1.91962 seconds