Re: Trouble customizing 2D plots in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg42156] Re: [mg42121] Trouble customizing 2D plots in Mathematica
- From: Omega Consulting <info at omegaconsultinggroup.com>
- Date: Sat, 21 Jun 2003 02:49:34 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
At 03:00 AM 6/19/2003, Kevin Gross wrote:
>Hi all,
>
>While I'm a devout Mathematica user, I do like the way some other
>plotting packages handle 2D plots with large y values. Specifically,
>some packages will factor out a common value, e.g., 10^3, from the
>y-axis labels and displays that common value above the y-axis. Below
>is my attempt at mimicking this behavior in Mathematica:
>
>(*Standard Mathematica plot with specific PlotRange*)
>p1 = Plot[x^2, {x, 0, 100}, Frame -> True, PlotRange -> {0, 6000}];
>
>(*Attempt at producing a nicer-looking plot*)
>p2 = Show[p1, FrameTicks -> {Automatic, {{0, 0}, {2000, 2}, {4000, 4},
>{6000, 6}, {8000, 8}, {10000, 10}}, Automatic, Automatic},
>DisplayFunction -> Identity];
>p3 = Graphics[Text["*\!\(10\^3\)", Scaled[{-0.05, 1.04}], {-1.5, 0}]];
>Show[p2, p3, PlotRange -> All, DisplayFunction -> $DisplayFunction];
>
>There are a couple of problems with my approach:
>
>1.) The text box only becomes visible when I use PlotRange->All.
>However, in some plots, I wish to specify a PlotRange different from
>All and still have the text box visible. For example:
>
>(*Must use PlotRange -> All*)
>Show[p2, p3, DisplayFunction -> $DisplayFunction];
>
>2.) The coordinates and offsets I've chosen, namely Scaled[{-0.05,
>1.04}], {-1.5, 0}, need to be changed if the image size is changed.
>I'd like to be able to resize the graphic without messing up the
>alignment of the text box relative to the y-axis. These coordinates
>and offsets are also dependent on the default text size, but this
>probably isn't too much of a problem. For example:
>
>(*Sensetive to resizing*)
>Show[p2, p3, ImageSize -> 8*72, PlotRange -> All, DisplayFunction ->
>$DisplayFunction];
>
>Can anyone offer a suggestion on how to accomplish my objective while
>avoiding these shortcomings? Or has someone already invented this
>wheel?
>
>Many thanks,
>
>Kevin
>--
>Kevin Gross
>Doctoral Student
>Air Force Institute of Technology
>Wright Patterson AFB, OH
The Rectangle primitive can be very useful for making different pieces of
graphics independent of one another.
p1 = Plot[x^2, {x, 0, 100}, Frame -> True, PlotRange -> {0, 6000}];
p2 = Show[p1, FrameTicks -> {Automatic, {{0, 0}, {2000, 2}, {4000, 4},
{6000, 6}, {8000, 8}, {10000, 10}}, Automatic, Automatic}];
p3 = Graphics[Text["*\!\(10\^3\)", {0, 0}]];
Note the change to p3. p2 and p3 are independent graphs in different
coordinate systems. We can combine those into a single graph by putting
each of them into a rectangle within a new coordinate system.
Show[Graphics[{Rectangle[{0, 0}, {1, .9}, p2],
Rectangle[{.05, .9}, {.15, 1}, p3]}]]
Changing the PlotRange of 1 graph doesn't change the overall coordinate
system, so the other graph won't move.
Show[Graphics[{Rectangle[{0, 0}, {1, .9},
Show[p2, PlotRange -> All, DisplayFunction -> Identity]],
Rectangle[{.05, .9}, {.15, 1}, p3]}]]
--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com