[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to plot continuously shaded area?



Lawrence Bleau wrote:
> Hello.   I've been tasked with making a smooth variation in color, from white
> through yellow, orange, into red, as part of a plot.  The plot currently has a
> white background, black axes, a grid, and black data points (lines connecting
> them).  I draw these using a combination of the commands plot, oplot, and axis.
> 
> The request if for the upper part of the plot, starting about halfway up the Y
> axis, to go gradually from white through the above mentioned colors into red by
> the time it reaches the top of the plotting area.
> 
> I know how to load the color table with tvlct, and have used this in the past
> (with the color keyword on oplot) to draw plots of different data sets in the
> same plotting region.  I also know about polyfill, which I've used before to
> shade rectangles.  However, polyfill seems to shade the entire rectangle with
> only a single color.
> 
> Am I doomed to drawing multiple rectangles, each with a different color index,
> and manually filling the color table with slightly different triples of R,G,B,
> to accomplish my goal?  Or is there another way I don't yet know about?  I saw
> there are shading routines, but these appear overpowering (3-D stuff I don't
> need).  Hints appreciated.
> 
> I'm running IDL V5.2 on OpenVMS AXP V7.1-2.  I'm writing to the Z buffer, and
> will eventually write the resultant plot to a GIF file (for now).  Thanks.

The following example shows how to position an image in the top half of
a plot. It does not have exactly the color table you desire: I'll leave
that to you.

Two external procedures are required:

IMDISP from
http://cimss.ssec.wisc.edu/~gumley/imdisp.html

COLORS from
http://cimss.ssec.wisc.edu/~gumley/colortools.html

PRO TESTPLOT

;- Get plot position
x = findgen(200) * 0.1
y = sin(x)
plot, x, y, /nodata, xstyle=4, ystyle=4

;- Create image
bottom = 16
ncolors = !d.table_size - bottom
image = bindgen(ncolors) + byte(bottom)
image = rebin(reform(image, 1, ncolors), ncolors, ncolors)

;- Display image in top half of plot  
colors
erase, 7
loadct, 33, bottom=bottom
position = [!x.window[0], 0.5 * total(!y.window), $
  !x.window[1], !y.window[1]]
imdisp, image, /noscale, position=position, /usepos, /interp

;- Plot data on top of image
position = [!x.window[0], !y.window[0], $
  !x.window[1], !y.window[1]]          
plot, x, y, /noerase, position=position, color=0

END

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley/