MathGroup Archive 2002

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

Search the Archive

RE: Bad Alignment of Y Axes

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37282] RE: [mg37248] Bad Alignment of Y Axes
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Mon, 21 Oct 2002 02:31:01 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----Original Message-----
> From: Max Ulbrich [mailto:ulbrich at biochem.mpg.de]
To: mathgroup at smc.vnet.net
> Sent: Friday, October 18, 2002 11:18 AM
> To: mathgroup at smc.vnet.net
> Subject: [mg37282] [mg37248] Bad Alignment of Y Axes
> 
> 
> Hi,
> 
> I have 2 or more separate Plots which have different y but the same x
> axes.
> Like:
> 
> Plot[Sin[x],{x,0,10}];
> Plot[1000Sin[x],{x,0,10}];
> 
> At the display and printout, the y axes are not aligned. Even 
> using the
> PlotRegion and ImageSize Options doesn't help. The only way I found
> was to align it manually with the mouse.
> Is there a package that solves the problem?
> The problem is, I have many, many plots to align...
> I use Mathematica 4.0.2.0 on a Windows 2000 PC.
> Who can help?
> 
> Max
> 
> 

Max,

this seems to be not so easy, because of Mathematicas way to scale pictures
containing text (and axes labels, tick labels etc. are texts). Texts are not
rescaled when the image size changes. Tom Wickham-Jones tells in his book
"Mathematica Graphics" in §10.2 at bottom of page 176:

"Thus Mathematica scales pictures to work with text when the PostScript is
displayed. The advantage of a scaling like this is that the picture looks
right. When a picture is made there is no need to ensure that enough space
is left for labels. The disadvantage is that it is not possible to set the
mapping of the graphic onto the page from Mathematica. This would make it
possible to do things like line up sub-pictures in a GraphicsArray,
something that is hard to do at present."

I found out a way to do this however, with minimal experimentation (one
parameter cannot be calculated, and depends on ImageSize, fonts, length of
texts etc.). 

Before showing this, let me mention that there is (or was) a package from
Michele Cappellari called MongoArray at
MathSource/Enhancements/Graphics/2D/0208-538 "Array of Framed Plots with
Shared or Inverted Axes".  He made this to plot astrophysical data, so it is
somewhat specialized, but you might like to try it out. Before doing so, fix
a bug which went unnoticed in prior versions of Mathematica. Replace the
last line of the function linearScale e.g. with

 If[# == 0``5 || Log[10., Abs[#]] < 4 && # == Round[#], Round[#], #] & /@ t

The idea of that package is to compose the plots and construct all
embellishments, FrameTicks, TickLabels etc. as graphic objects by own means
at the composed graphics..

Here now my method which uses GraphicsArray and thus preserves the full
power of plotting. For example let's have two plots

{g1, g2} = {Plot[Sin[x]^3, {x, 0, 2Pi}, GridLines -> {Pi/2 Range[4], None}],
    Plot[500*Tan[x], {x, 0, 2Pi}, PlotRange -> {{0, 2 Pi}, {-12000, 12000}},

      GridLines -> {Pi/2 Range[4], None}]}

Show[GraphicsArray[{{g1}, {g2}}]]

...does not align the plots properly, but

Show[GraphicsArray[
    Map[Show[FullGraphics[#], DisplayFunction -> Identity, 
          PlotRegion -> {{0.1, 1}, {0, 1}}, 
          PlotRange -> 
            Tr[{FullOptions[g1, PlotRange], FullOptions[#, PlotRange]},
List, 
              2]] &, {{g1}, {g2}}, {2}], GraphicsSpacing -> -0.08], 
  ImageSize -> 500]

The trick is to shrink the PlotRegion such that the FullGraphics of all
parts can be displayed in the plot area, and to properly adjust the
PlotRanges. Of course you may include more than two plots (of functions with
same domain), instead of g1 to define the PlotRange for x, you may take any
of the plots involved. I reduced the GraphicsSpacing to better demonstrate
the perfect match. The experimental parameter is the left edge of PlotRegion
(0.1). You may lower it for larger images or must increase for larger tick
labels. 

More complicated is to align plots with different aspect ratios, since (from
Help:) "GraphicsArray sets up identical rectangular display areas for each
of the graphics objects it contains" However I can trick that out (with more
complicated manipulations of PlotRegion). The remaining problem is to adjust
the final total display area. If Wolfram's show me the code of GraphicsArray
(or give me more documentation) I could make it (without any modifications
to GraphicsArray); until then, some experimentation is needed. If you really
need that, I can tell you how, otherwise we might code our own version of
GraphicsArray. But I dislike to do that, because my philosophy is to stick
to standards as long as possible.

--
Hartmut Wolf



  • Prev by Date: RE: RE: List processing
  • Next by Date: Error handling with MathLink
  • Previous by thread: Re: Bad Alignment of Y Axes
  • Next by thread: Checking the Results of NDSolve