Discussion:
How to have shaded background for just a portion of a plot?
(too old to reply)
nafod40
2003-12-19 12:09:15 UTC
Permalink
Hola,

Anyone know how to shade the background of just a portion of a plot?
I've tried placing shaded rectangles behind the plot using Show,
DisplayTogether, Epilog, and Prolog and all permutations (2^4) thereof.
I have a framed and gridded plot, and I want to shade a region.

Rectangle always overwrites the axes and grids. I would rather not
create the axes and grids myself.
Owen, HL (Hywel)
2003-12-20 10:58:27 UTC
Permalink
It depends on the ordering of the plot and the background in any Show
commands you use:

e.g. here's a plot:

plot = Plot[Sin[x], {x, 0, 2Pi}]

This way the plot is behind the rectangles:

Show[plot, Graphics[{Hue[.77], Rectangle[{0, 0}, {
5, 1}], Hue[.17], Rectangle[{3, 0}, {4, 2}]}]]

This way the plot is on top of the rectangles:

Show[Graphics[{Hue[.77], Rectangle[{0, 0}, {5,
1}], Hue[.17], Rectangle[{3, 0}, {4, 2}]}], plot, Frame -> True]

Frame->True is ok for the axes, but you're right that the GridLines are
overwritten.
-----Original Message-----
Sent: 19 December 2003 11:57
Subject: How to have shaded background for just a
portion of a
plot?
Hola,
Anyone know how to shade the background of just a portion of a plot?
I've tried placing shaded rectangles behind the plot using Show,
DisplayTogether, Epilog, and Prolog and all permutations
(2^4) thereof.
I have a framed and gridded plot, and I want to shade a region.
Rectangle always overwrites the axes and grids. I would rather not
create the axes and grids myself.
David Park
2003-12-20 11:05:36 UTC
Permalink
You can use the AxesFront -> True option from the Graphics`FilledPlot
package.

I have always thought that AxesFront should be a regular graphics option
because it has many uses in addition to filled plots, as your case
illustrates.

David Park
***@earthlink.net
http://home.earthlink.net/~djmp/

From: nafod40 [mailto:***@business.com]

Hola,

Anyone know how to shade the background of just a portion of a plot?
I've tried placing shaded rectangles behind the plot using Show,
DisplayTogether, Epilog, and Prolog and all permutations (2^4) thereof.
I have a framed and gridded plot, and I want to shade a region.

Rectangle always overwrites the axes and grids. I would rather not
create the axes and grids myself.
nafod40
2003-12-23 10:27:08 UTC
Permalink
Post by David Park
You can use the AxesFront -> True option from the Graphics`FilledPlot
package.
I have always thought that AxesFront should be a regular graphics option
because it has many uses in addition to filled plots, as your case
illustrates
Thanks to all for the answers. I used David's way. I agree the AxesFront
option should be available in the kernel.

John C. Erb, Ph.D.
2003-12-20 11:08:42 UTC
Permalink
Try the Rectangle function.
To make an area of some color, you could
make a plot where the plot is in the same color
as the background. For Example

plotOne=Plot[Sin[x],{x,0,2Pi},Axes->False,
PlotStyle->{RGBColor[1,0,0]},Background->RGBColor[1,0,0]];

Then have your main plot. For example

plotTwo=Plot[Cos[x],{x,0,2Pi}];

Then Show these together using the Rectangle function

Show[Graphics[{Rectangle[{0,0},{1,1},plotTwo],
Rectangle[{0.45,0.55},{0.75,0.9},plotOne]}]];

You could use $DisplayFunction->Identity, if you didn't want to display
the plotOne and plotTwo separately, but only the combined plot.

I can't take credit for this idea.
See Applied Mathematica, Getting It Started Getting It Done,
By Shaw & Tigg, Section 5.21.


John C. Erb
Email: ***@prodigy.net

-----Original Message-----
From: nafod40 [mailto:***@business.com]
Subject: How to have shaded background for just a portion of a
plot?

Hola,

Anyone know how to shade the background of just a portion of a plot?
I've tried placing shaded rectangles behind the plot using Show,
DisplayTogether, Epilog, and Prolog and all permutations (2^4) thereof.
I have a framed and gridded plot, and I want to shade a region.

Rectangle always overwrites the axes and grids. I would rather not
create the axes and grids myself.
Peter Hahn
2003-12-23 10:25:05 UTC
Permalink
Hi,

when in need to shade an area on only one axis (i.e. 0<x<2), I often use
GridLines with a very narrow spacing of the gridlines in order to make
them overlap. Obviously, this will not work if you want to have an area
which has limits on both axes (ie. 0<x<2 && 0<y<2).

Peter
Post by nafod40
Hola,
Anyone know how to shade the background of just a portion of a plot?
I've tried placing shaded rectangles behind the plot using Show,
DisplayTogether, Epilog, and Prolog and all permutations (2^4) thereof.
I have a framed and gridded plot, and I want to shade a region.
Rectangle always overwrites the axes and grids. I would rather not
create the axes and grids myself.
Continue reading on narkive:
Loading...