On 9/11/2011 12:14 PM, David Fanning wrote:
> Folks,
>
> Because what I assumed was impossible has turned out to be
> possible, and because I don't want others to struggle
> for three days in frustration, Coyote and I have
> decided to share the secret of how to produce a simple
> contour plot using the IDL 8.1 function graphics
> commands. (The alternative, of course, would be to try to
> get rich by writing the only IDL 8.1 graphics documentation
> worth a damn, but the audience seems small to us.)
>
> You can find the article here:
>
> http://www.idlcoyote.com/ng_tips/elephant.php
>
> Cheers,
>
> David
>
>
There's an easier way to make this plot, but you have to work with the
fact that COLORBAR wants 256 values and is tied to the data.
I've used code similar to what I posted earlier
[ https://groups.google.com/d/msg/comp.lang.idl-pvwave/QHJmvrK ybz/WMR2aD5g0P8J],
and I put in a few comments to show where my code differs from yours.
I've tested this on my laptop (64-bit Win XP + 32-bit Linux (Ubuntu
10.10)) and the Tech Support Mac running Lion.
mp
pro ng_discrete_colorbar1
compile_opt idl2
data = randomu(-3L, 9, 9)
levels = [0.0, 0.25, 0.5, 0.75, 1.0] ; note top level
; COLORBAR wants 256 colors, so replicate the 4 desired colors.
colors = [[!color.red], [!color.blue], [!color.green], [!color.yellow]]
n_colors = n_elements(colors)
step_ct = congrid(colors, 3, 256)
w = window(dimensions=[750, 400])
w.refresh, /disable
c = contour(data, $
/current, $
c_value=levels, $
/fill, $
position=[0.1, 0.1, 0.9, 0.8], $
rgb_table=step_ct, $
rgb_indices=bytscl(indgen(n_colors))) ; this is a bug in 8.1
over = contour(data, $
/current, $
c_value=levels, $
axis_style=0, $
font_size=10, $
/c_label_show, $
/c_use_label_orientation, $
c_label_interval=0.6, $ ; thin the number of labels
position=[0.1, 0.1, 0.9, 0.8])
cb = colorbar(target=c, $
tickname=string(levels, format='(f4.2)'), $ ; use the levels
position=[0.1, 0.90, 0.9, 0.95])
w.refresh
end
|