Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Marking a (rectangular) zone in a standard 2D plot using "Rectangle"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49763] Re: [mg49740] Marking a (rectangular) zone in a standard 2D plot using "Rectangle"
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 30 Jul 2004 06:02:15 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Rainer,

This is an excellent example of how the normal Mathematica graphics paradigm
befuddles even quite intelligent people. We want to draw the Rectangle
first, then the graph, and then we want to use the AxesFront -> True option,
which is buried away in the Graphics`FilledPlot` standard package. Then we
run into the problem that Plot will not take AxesFront as an option. So we
have to do something like the following (as an example).

Needs["Graphics`FilledPlot`"]
Needs["Graphics`Colors`"]

plot1 =
  Plot[Sin[x], {x, 0, 6Pi},
    PlotStyle -> Black,
    Prolog -> {Yellow, Rectangle[{2Pi, -1}, {4Pi, 1}]},
    Background -> Linen];

Show[plot1, AxesFront -> True];

(If we hadn't put in the PlotStyle -> Black, the Yellow would have remained
from the Prolog.) It's not that difficult, but users don't think of the
Prolog option, don't think of just putting Yellow before the Rectangle, and
don't think of the FilledPlot package.

With the DrawGraphics package from my web site below, one can just draw the
graphics primitives in the correct order and the FilledPlot package is
automatically loaded whenever AxesFront is used, and Graphics`Colors` is
also automatically loaded.

Then the plot would be done this way in one statement.

Needs["DrawGraphics`DrawingMaster`"]

Draw2D[
    {Yellow,
      Rectangle[{2Pi, -1}, {4Pi, 1}],
      Black,
      Draw[Sin[x], {x, 0, 6Pi}]},
    Axes -> True,
    AxesFront -> True,
    Background -> Linen];

You could also directly add curves produced by any of the other 2D plot
types or other primitives such as Line, Polygon, Circle or Text.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: Rainer [mailto:wilhelm.rainer at gmx.net]
To: mathgroup at smc.vnet.net


Hi,
I'd like to mark a rectangular zone {{xmin,ymin},{xmax,ymax}} in a
standard 2D-plot (of a mathematical function) by a coloured rectangle
(e.g. in bright yellow). This is to highlight a part of the plot. To
do this, I have tried the following:

First I created the plot of the function (defined as f[x]):

p[1]=Plot[f[x], ..., DisplayFunction -> Identity);

The option "DisplayFunction -> Identity" tells Mathematica *not* to
plot immediately.
Then I create the rectangle using:

p[2] = Show[Graphics[Rectangle[{xmin, ymin}, {xmax,ymax}],
    ColorOutput -> RGBColor[1, 0, 0], DisplayFunction -> Identity];

Finally I am plotting both of them using:

Show[{p[1], p[2]}, DisplayFunction -> $DisplayFunction];

The problems are:

* The rectangle overlaps the 2-D-plot, and I would like to use it just
as a "transparent" background, i.e. I would like that the curve of
f[x] stays visible in the highlighted zone.

* I do not know how to change the color of the rectangle. Obviously
"ColorOutput" is not the right option ... I've also tried
ColorFunction but also that one does not do what I'd like it to do.

* If I change the order in the above Show command: p[2],p[1] instead
of p[1],p[2], the rectangle is in the background but the axes of the
2d plot and all its grid lines vanish.

I appreciate any helpful comment!
Thanks
Rainer




  • Prev by Date: Re: RE: Combinations
  • Next by Date: Re: PutAppend Command and Data Output
  • Previous by thread: Marking a (rectangular) zone in a standard 2D plot using "Rectangle"
  • Next by thread: Re: Fibonacci[1,000,000,000] contains 208,987,640 decimal digits