Re: Color background with PLOT [message #51430] |
Sat, 18 November 2006 17:00 |
Jeff Hester
Messages: 21 Registered: December 2001
|
Junior Member |
|
|
David Fanning wrote:
> Matt Harner writes:
>
>
>> I'd like to have a color background on a plot using direct graphics.
>> Instead of the built in background using the BACKGROUND keyword to
>> PLOT, I'd like the background to only be behind the plotted data, not
>> the entire window (axis, ticks, title, etc). The only way I have found
>> to do this is to draw a colored box with POLYFILL in the area that I
>> desire, but then the axis tick marks are under the polygon. Is there
>> any way to do this while still maintaining the plot tick marks?
>
>
> If you position your plot with the POSITION keyword, then
> you can draw your background polygon first into that position,
> then draw your plot with the NOERASE keyword set. (You might
> have to erase the window first with the ERASE command. This
> would be a good time to get the area outside the polygon
> the color you want, since you can use the COLOR keyword
> here as well.)
>
> Direct graphics commands just put pixels on top of pixels,
> so sometimes you have to "layer" your graphics commands
> to achieve the results you want. The NOERASE keyword is
> a great help when you are re-drawing axis tick marks and
> the like. :-)
>
> Erase, COLOR=FSC_COLOR('ivory')
> p = [0.15, 0.15, 0.9, 0.9]
> PolyFill, [p[0],p[0],p[2],p[2],p[0]], $
> [p[1],p[3],p[3],p[1],p[1]], $
> COLOR=FSC_COLOR('sky blue'), /NORMAL
> Plot, findgen(11), COLOR=FSC_COLOR('red'), $
> POSITION=p, /NOERASE
>
> Cheers,
>
> David
Or you can be exquisitely inelegant and draw your axes with
plot,/nodata, do the polyfill using data coordinates, then do your plot
with plot,/noerase.
For various reasons (like inertia) I mostly use direct graphics, so
frequently redo things in a plotting sequence to get the layering right.
Cheers,
Jeff
|
|
|
|
Re: Color background with PLOT [message #51436 is a reply to message #51435] |
Sat, 18 November 2006 09:32  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Matt Harner writes:
> I'd like to have a color background on a plot using direct graphics.
> Instead of the built in background using the BACKGROUND keyword to
> PLOT, I'd like the background to only be behind the plotted data, not
> the entire window (axis, ticks, title, etc). The only way I have found
> to do this is to draw a colored box with POLYFILL in the area that I
> desire, but then the axis tick marks are under the polygon. Is there
> any way to do this while still maintaining the plot tick marks?
If you position your plot with the POSITION keyword, then
you can draw your background polygon first into that position,
then draw your plot with the NOERASE keyword set. (You might
have to erase the window first with the ERASE command. This
would be a good time to get the area outside the polygon
the color you want, since you can use the COLOR keyword
here as well.)
Direct graphics commands just put pixels on top of pixels,
so sometimes you have to "layer" your graphics commands
to achieve the results you want. The NOERASE keyword is
a great help when you are re-drawing axis tick marks and
the like. :-)
Erase, COLOR=FSC_COLOR('ivory')
p = [0.15, 0.15, 0.9, 0.9]
PolyFill, [p[0],p[0],p[2],p[2],p[0]], $
[p[1],p[3],p[3],p[1],p[1]], $
COLOR=FSC_COLOR('sky blue'), /NORMAL
Plot, findgen(11), COLOR=FSC_COLOR('red'), $
POSITION=p, /NOERASE
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.")
|
|
|