On 9/12/2011 11:12 AM, David Fanning wrote:
> David Fanning writes:
>
>> I'll see what I can learn from that example if I remove
>> the TICKNAME keyword. :-)
>
> Ah, Mark, all I did to your code was comment out the
> TICKNAME keyword and run the program. This is the
> output I got:
>
> http://www.idlcoyote.com/misc/mark_piper_contour.png
>
> I'm pretty sure that's not what you must be seeing!
> I'm running IDL 8.1 on a Windows 7, 64-bit OS:
>
> IDL> print, !version
> { x86_64 Win32 Windows Microsoft Windows 8.1 Mar 9 2011 64 64}
>
> Any ideas?
>
> Cheers,
>
> David
>
Ack! Yes, I made a mistake. Sorry about that. Lesson: I shouldn't post
to the newsgroup while distracted. Counting the colors with N_ELEMENTS
was the problem. Here's a revised version.
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]]
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(4))) ; 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
|