[Date Index]
[Thread Index]
[Author Index]
Aligning Graphics in V6
*To*: mathgroup at smc.vnet.net
*Subject*: [mg75702] Aligning Graphics in V6
*From*: Hugh <h.g.d.goyder at cranfield.ac.uk>
*Date*: Wed, 9 May 2007 04:20:59 -0400 (EDT)
The problem of aligning two plots or graphics, one above the other, so
that the x axes correspond has been an issue discussed in mathgroup
for as long as I remember. Previous heros of mathgroup, such as David
Park, wrote special codes to overcome the difficulty. In version 6 we
have a solution.
The problem is illustrated below by using GraphicsColumn. As may be
seen the large y labels on the lower plot cause the width of the
plotting region to be shrunk compared to the upper plot.
There may be several solutions in version 6 but I give one below that
uses Inset and ImagePadding. The difficulty with formatting this plot
is that the space for numbers and text must be given in the text units
of points (with 72 points per inch) while the coordinates making up
the plot use their own coordinate units. Let the width of the bounding
box, in points, be w, this may be set using ImageSize. Let the
distance between the edges of the bounding box and the region
containing the plot be {{l, r},{b, t}} ie {{left, right},{bottom,
top}}; this is set in points by ImagePadding. The length of the x-axis
in points is thus w - l - r. If other options are set, such as
ImageMargins, then the length of the x-axis will be further reduced.
I use one trick. I set up the final plot in points and use the ability
of Inset to rescale the graphics coordinates.
In the first example below I am aiming to have both x-axes of length
5 inches and both y axes of height 2 inches with 1/3 inch between the
plots. I add an additional length of one inch to the left of the axes
for text in numbers and labels. In the second example I plot phase and
modulus ( a Bode plot) for a complex function f where the x-axes are
again 5 inches but the phase y-axis is 1 inch high and the modulus y-
axis is 3 inches. The plots are separated by 1/3 of an inch.
If you plot these plots via a printer then Mathematica shrinks the
plots by a factor of 0.8. I have yet to find out where this is set in
V6.
Are there simpler ways to do this? Is this illustrated in the help
documentation anywhere? Could the FrameLabels be aligned?
Hugh Goyder
GraphicsColumn[{Plot[Sin[x], {x, 0, 5*Pi}], Plot[10^5*Cos[x], {x, 0,
5*Pi}]}]
Graphics[{
Inset[
Plot[Sin[x], {x, 0, 5*Pi},
PlotRange -> {{0, 5*Pi}, {-1, 1}},
PlotRangePadding -> {None, None},
BaseStyle -> {FontFamily -> "Times", FontSize -> 12},
Frame -> True,
FrameLabel -> {None, "Amplitude 1"},
AspectRatio -> 2/5,
ImagePadding -> {{72, 1}, {24, 12}}],
{0, 2.3333*72}, {0, -1}, 6*72],
Inset[
Plot[10^5*Cos[x], {x, 0, 5*Pi},
PlotRange -> {{0, 5*Pi}, {-10^5, 10^5}},
PlotRangePadding -> {None, None},
BaseStyle -> {FontFamily -> "Times", FontSize -> 12},
Frame -> True, FrameLabel -> {"Time", "Amplitude 2"},
AspectRatio -> 2/5,
ImagePadding -> {{72, 1}, {48, 12}}],
{0, 0}, {0, -10^5}, 6*72]},
PlotRange -> {{0, 5*72}, {0, 4.3333*72}},
AspectRatio -> 4.3333/5,
ImageSize -> 6*72,
ImagePadding -> {{72, 1}, {48, 12}}]
f[w_, z_] := 1/(1 - w^2 + 2*I*z*w)
Graphics[{
Inset[Plot[
{Arg[f[w, 0.01]], Arg[f[w, 0.05]], Arg[f[w, 0.1]]},
{w, 0, 2},
PlotRange -> {{0, 2}, {-Pi, 0}},
PlotRangePadding -> {None, None},
BaseStyle -> {FontFamily -> "Times", FontSize -> 12},
Frame -> True,
FrameLabel -> {None, "Phase"},
AspectRatio -> 1/5,
ImagePadding -> {{72, 1}, {24, 12}}],
{0, 3.33333*72}, {0, -Pi}, 6*72],
Inset[LogPlot[
{Abs[f[w, 0.01]], Abs[f[w, 0.05]], Abs[f[w, 0.1]]},
{w, 0, 2},
PlotRange -> {{0, 2}, All},
PlotRangePadding -> {None, None},
BaseStyle -> {FontFamily -> "Times", FontSize -> 12},
Frame -> True,
FrameLabel -> {"Frequency", "Modulus"},
AspectRatio -> 3/5,
ImagePadding -> {{72, 1}, {48, 12}}],
{0, 0}, {0, Log[10, 0.1]}, 6*72]},
PlotRange -> {{0, 5*72}, {0, 4.3333*72}},
AspectRatio -> 4.3333/5,
ImageSize -> 6*72,
ImagePadding -> {{72, 1}, {48, 24}}]
Prev by Date:
**Re: Re: Pi upto a Billion Digits**
Next by Date:
**Re: Eigenvalues in Mathematica 6.0.0 are SLOW**
Previous by thread:
**elliptic integral**
Next by thread:
**Re: Re: Format->Magnification does not work**
| |