Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Help with "recession bar" graph
Replies: 6   Last Post: Feb 13, 2013 4:48 AM

 Messages: [ Previous | Next ]
 David Park Posts: 1,560 Registered: 5/19/07
Re: Help with "recession bar" graph
Posted: Feb 10, 2013 3:35 AM

Alan,

All of which brings up a topic that confuses many users doing graphics.
There are two kinds of Options that affect the look of a plot. The first
kind affect the drawn lines, curves, surfaces and primitives. Things such as
color, shading, Mesh, PlotPoints and MaxRecursion. The second kind of Option
affects the parts of the graphic that determine the overall look independent
of the "drawn" items: such things as AspectRatio, ImageSize, Frame, Axis,
Ticks, Background, PlotRegion, etc. There is at least one option, PlotRange,
that may affect both aspects of the plot. For example, if you are combining
a ContourPlot with other elements, you may need the z PlotRange to capture
all of the contours, and the x and y ranges for the overall plot.

With the Show statement Mathematica picks up the Options from the first plot
in the Show statement and they override Options from subsequent plots. This
doesn't make a lot of sense and confuses many users. So, for example, if you
had an Epilog Option in the second plot that logically went with the second
plot, you would have to shift it to the first plot. However, you can also
put Options at the end of the Show statement and these take precedence.

So with Bob Hanlon's example:

data = {38.396359394355414`, 72.27272309523107`, 89.29538328240793`,
72.10010639242938`, 82.58607698201098`, 18.6576446975194`,
33.27870983668225`, 21.4169865528564`, 27.143317794267958`,
56.831020645157224`, 97.91895556654552`, 53.699909198741835`,
62.45884842291329`, 43.57174038250221`, 5.572069539912178`,
47.64601720765782`, 57.36520060575606`, 11.616476185686125`,
53.621120873396194`, 86.51670206163143`, 46.158001732049314`,
91.79901697376656`, 56.56864196802621`, 68.80447171646065`,
69.71270226145879`, 9.193667545986898`, 12.322285539970679`,
84.54474541006726`, 37.46708245474912`, 70.19095794556748`,
21.368052894967576`, 95.70714721558335`, 19.184901239515995`,
12.369028572198587`, 97.66742717262244`, 64.70934352032668`,
1.1657357274066413`, 57.74269869413277`, 58.529638656649155`,
34.40274725318369`, 52.38021809465195`, 64.42731199035626`,
54.74507564841295`, 32.199884547032894`, 64.85420465012712`,
26.538659912812435`, 43.037739816388466`, 25.366295485189113`,
7.604466054852992`, 92.16216075731677`};

Just add Options at the end, and here I give myself a tiny advantage by also
adding some arrows to the graphic.

Show[RegionPlot[{6 <= x <= 13, 19 <= x <= 25, 39 <= x <= 46}, {x, 0,
50}, {y, 0, 100}, BoundaryStyle -> None], ListLinePlot[data],
Epilog ->
{Arrowheads[{-0.02, 0.02}], Arrow[{{6, 95}, {13, 95}}],
Arrow[{{19, 95}, {25, 95}}], Arrow[{{39, 95}, {46, 95}}]},
Frame -> False,
AspectRatio -> 1/2,
Axes -> True,
ImageSize -> 400]

With the Presentations Application this would be done as follows:

<<Presentations`

Draw2D[
{RegionDraw[{6 <= x <= 13, 19 <= x <= 25, 39 <= x <= 46}, {x, 0,
50}, {y, 0, 100}, BoundaryStyle -> None],
ListLineDraw[data],
Arrow[{{6, 95}, {13, 95}}], Arrow[{{19, 95}, {25, 95}}],
Arrow[{{39, 95}, {46, 95}}]},

AspectRatio -> 1/2,
Axes -> True,
ImageSize -> 400]

Constructs such as RegionDraw and ListLineDraw do not take or use any of the
overall Graphics Options and they would show as Red if used. RegionDraw does
accept BoundaryStyle because that affects the graphics primitives returned.
We just draw one thing after another, including the Arrows, without having
to use Epilog or Graphics level jumping. The overall plot Options ALWAYS go
at the end where we might expect them since they have nothing to do with the
other items.

David Park
djmpark@comcast.net
http://home.comcast.net/~djmpark/index.html

From: Alan G Isaac [mailto:alan.isaac@gmail.com]

On 2/8/2013 11:12 AM, Bob Hanlon wrote:
> Show[
> RegionPlot[
> {6 <= x <= 13, 19 <= x <= 25, 39 <= x <= 46},
> {x, 0, 50}, {y, 0, 100},
> BoundaryStyle -> None],
> ListLinePlot[data]]

This is informative, but it does not meet my needs.
You put the RegionPlot first, as needed for proper overlay, but then it
hijacks the plot properties.
I'm really looking for something equivalent to Matplotlib's axvspan, in
order to add a Graphics element to an existing plot.
For now I'm putting a rectangle in the Prolog and handling the y-coordinates
myself, but I'd welcome a better solution.

Thanks,
Alan Isaac

Date Subject Author
2/9/13 Alan
2/10/13 David Park
2/13/13 Alexei Boulbitch
2/11/13 Alan