Re: An IDL cron job, true color plots, Xvfb, Z-buffer, and all sorts of troubles [message #58587 is a reply to message #58584] |
Thu, 07 February 2008 06:58   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Spon writes:
> I'm sure David (most likely) will be along shortly with an explanation
> of how to solve your problem in a much more sensible way, and will do
> so more eloquently than I could - even if I knew how ;-)
Oh, dear. Doesn't anyone read the articles I put on my
web page anymore, or are they just so poorly written no
one cares!? :-(
But, do yourself a favor, and at least read this article:
http://www.dfanning.com/color_tips/working_with_color.pdf
This code is so dead simple that the only reason it
doesn't work is that just about everything is done wrong. :-)
Here are a couple of rules:
1. If you care about PostScript color, don't use the color
indices at the top and bottom of the color table to specify
any of them. Specifically, don't use !P.COLOR and
!P.BACKGROUD, since these are almost always pointed to the
top and bottom of the color table.
2. There are commands, such as WINDOW and ERASE, that we
often find in programs that work great in a display device,
but which either don't work or work differently (and
disastrously, usually) in the PostScript device. These
have to be protected. They are usually protected like this:
IF (!D.FLAGS AND 256) NE 0 THEN Window
This modified program will work on your display and in
PostScript, *if* you set your PostScript device up correctly,
which I have my doubts about, but see more below:
pro plot_test, indices, color_scale,$
title=title
if n_elements(title) eq 0 then title=''
; example simple grid of 4 points:
x_pos=[1., 2., 1., 2.]
y_pos=[1.,1.,2.,2]
; Load colors for the plot
tvlct, 255, 255, 255, 0, 10 ; White loaded at color index 10
tvlct, 0, 0, 0, 11 ; Black loaded at color index 11
; Indexed color on your display device, skip if in PS
if (!d.flags and 256) ne 0 then Device, decomposed = 0
;plot, the center points for each detector:
plot, x_pos, y_pos, xrange=[0,3],yrange=[0,3],
/xstyle,/ystyle,/iso,psym = 3, title = title,
color=11, background=10
; Load the colors for the polyfill and color bar.
LoadCT, 33
; determine the color scale to use
color_scale=float(color_scale)
color_values = ((color_scale - min(color_scale))/(max(color_scale)-
min(color_scale)))* 255
;plot circles filled with the colors in the scale
for I=0,n_elements(indices)-1 do begin
polyfill, circle(x_pos[indices[I]],y_pos[indices[I]],0.25),
color=color_values[I]
endfor
colorbar, /vertical, format='(F6.2)',$
range=[min(color_scale),max(color_scale)],
annotatecolor='black'
;or, alternatively...
;
; load colors for the colorbar.
;loadct, 33, ncolors=253
;tvlct, 0, 0, 0, 254
;colorbar, /vertical, format='(F6.2)',$
; range=[min(color_scale),max(color_scale)],
; color=254, ncolors=253
end
3. Make sure your PostScript device is set up correctly.
If you insist on not using PSCONFIG to do this (and I don't
know why this is the case, since this program was designed
to be so dead simple that it solves 90% of PostScript problems
before you even know they are problems), then at least be
sure you set BITS_PER_PIXEL=8 and COLOR=1. This is almost
certainly why your PostScript output is "grainy".
You can find probably another dozen rules of so, discussed
in excruciating detail, on my web page:
http://www.dfanning.com/documents/tips.html#PostScript
Having said all this, I certainly wouldn't use PostScript to
solve this problem. :-)
If the Z-Graphics buffer doesn't accept the DEVICE, DECOMPOSED=0
command, then you are using an old version of IDL. But, in any
case, you now know how to protect this command. :-)
Since this article is already longer than the two lines most
people tend to read, I won't go into the details of how to
create a PNG file in the Z-buffer, except to say Chris is
right, use TVREAD. It will solve all your problems.
In fact, all your problems would be solved by judicious use
of these four programs:
PSCONFIG
FSC_COLOR
TVREAD
TVIMAGE
These were created to *specifically* solve PostScript problems
and make it easy to write programs that just work *everywhere*. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|