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

Home » Public Forums » archive » Re: Contour Plot with Handful of Colors
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: Contour Plot with Handful of Colors [message #77547 is a reply to message #77546] Thu, 08 September 2011 07:42 Go to previous message
Mark Piper is currently offline  Mark Piper
Messages: 198
Registered: December 2009
Senior Member
On 9/7/2011 8:45 PM, David Fanning wrote:
> Folks,
>
> I am trying to reproduce a filled contour plot with
> a colorbar with a handful (9, in this case) of colors.
> Does anyone know how to produce a function graphics
> color bar with less than 256 colors? Also, I can't
> get my function graphics filled contour to use the
> colors I am trying to assign to it. :-(
>
> Any ideas?
>

Hi David,

It's possible, but you have to mess with the color tables.

mp

pro ng_discrete_colorbar
compile_opt idl2

; Example function to plot with a range of [0,100].
d = dist(41)
fmax = 100.0
f = d / max(d) * fmax

; Explicitly set 11 contour levels: [0, 10, 20, ... 100].
n_levels = 11
levels = findgen(n_levels)/(n_levels-1)*fmax

; Make a step color table for the contour plot. The color table
'step_ct'
; is a [256,3] array, but there are only n_levels=11 distinct colors (to
; check, load & view the color table in XPALETTE). The indices into
the color
; tables (both original and step) are contour levels interpolated to
the
; range of color table indices (i.e., the byte range).
ct_number = 4
ct_indices = bytscl(levels)
loadct, ct_number, rgb_table=ct, /silent
step_ct = congrid(ct[ct_indices, *], 256, 3)

; Display the example function using the step color table and the
; interpolated indices.
c1 = contour(f, $
c_value=levels, $
rgb_table=step_ct, $
rgb_indices=ct_indices, $
/fill, $
margin=[0.15, 0.20, 0.15, 0.15], $ ; leave room for colorbar
title='Max = ' + strtrim(fmax,2), $
window_title='Discrete Colorbar Example')

; The colorbar needs n_levels+1 ticks for labels to line up correctly.
tick_labels = [strtrim(fix(levels), 2), ''] ; append empty string
cb = colorbar( $
target=c1, $
ticklen=0, $
major=n_levels+1, $
tickname=tick_labels, $
font_size=10, $
position=[0.2, 0.07, 0.8, 0.1])
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Direct vs Function Graphics Contour Plots
Next Topic: Need a Coffee Break?

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

Current Time: Fri Oct 10 01:10:27 PDT 2025

Total time taken to generate the page: 0.64221 seconds