Re: setting default background color, etc [message #8901 is a reply to message #8900] |
Wed, 14 May 1997 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Melissa Nischan writes:
> I am very new to IDL, and have what I believe should be a basic
> question (but I couldn't find anything in the FAQ about it): when I start
> IDL and plot something, I always get white on a black background. I
> discovered that if I set !p.background I can change that, but I was
> wondering how do I set the default background to be something other than
> black? It's a pain to have to set it each time. (I use IDL on a
> UNIX machine)
Hi Melissa,
By default, IDL sets the background color to color index 0. Thus,
to change the background color, you need to load some other
color into this index. For example, you could load (heaven forbid!)
a yellow color in this index like this:
IDL> TVLCT, 255, 255, 0, 0
You could even do this in an IDL startup file.
The problem with this approach is that every time you load
a new color table you are likely to write over this index.
What I usually do is save about four or five colors at the
top of my color table for "drawing colors". Then I make sure
I use these colors for plotting, etc. And I make sure I don't
write over them when I change color tables.
For example, here are three drawing colors (charcoal, yellow,
and green, loaded into the last three elements of the color
table. You might do this in an IDL startup file:
; Find out how many colors you have.
Window, /Pixmap, /Free, XSize=10, YSize=10
WDelete, !D.Window
ncolors = !D.N_Colors
; Data colors--leave top three colors alone.
dataColors = ncolors - 3
; Load "drawing" colors (charcoal, yellow, green).
TVLCT, [120, 255, 0], [120, 255, 255], [120, 0, 0], dataColors
backgroundColor = dataColors
plotColor = dataColors + 1
oplotColor = dataColors + 2
!P.Background = backgroundColor
!P.Color = plotColor
Now, you can just draw a plot, like this:
data = Findgen(11)
Plot, data
Or, you can specify the colors specifically, like this:
Plot, data, Color=plotColor, Background=backgroundColor
OPlot, Reverse(data), Color=oplotColor
When you load a new color table, be sure you only load the
data colors, and don't write over your drawing colors. Do
something like this:
XLoadCT, NColors=datacolors
There are a lot of color tips like this on my Coyote's Guide
to IDL Programming web page. You will also find programs
(e.g. GETCOLOR, CHGCOLOR, XCOLORS, etc.) that will help you work
with colors in IDL.
Good luck!
David
----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
Customizable IDL Programming Courses
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
|
|
|