MathGroup Archive 1996

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

Search the Archive

Re: Aligning Graphs in GraphicsArray

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3960] Re: [mg3882] Aligning Graphs in GraphicsArray
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Mon, 13 May 1996 01:45:51 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Dirk Kautz <kautz at tyto.bio2.rwth-aachen.de>
in [mg3882] Aligning Graphs in GraphicsArray

asks, does anybody know how to align the y-axes of plots with ticks  
of different width in a GraphicsArray ?
Example: in
Show[GraphicsArray[{{Plot[x,{x,0,100}]},{Plot[100 x,{x,0,100}]}}]]
the Y-Axes don't align, and ask for a way round this

********

Dirk,
Below are two ways of dealing with your example - they may provide  
a basis for a more general solution.

Allan Hayes
hay at haystack.demon.co.uk

****

Put
	g1 =Plot[x,{x,0,100}]
	g2 =Plot[100 x,{x,0,100}]

We need to pad out the y-axis tick labels in g1 with spaces at the  
front so that they are as long as the longest y-axis label in g2,  
which is 10000.

Find the primitives used for the ticks in g1
	fg1 = FullGraphics[g1]
Look inside -Graphics- by evaluating
	InputForm[fg1]
By inspection identify the index of the y-ticks definition as   
1,2,4 and pad the tick labels  as  required.
	pg1 =
	   MapAt[
	      (#/.Text[n_?NumberQ, r__] :> Text[PaddedForm[n,5],r])&,
	      fg1,
	      {1,2,4}
	   ];
It seems that we need to use PlotRange -> All to display the tick  
labels fully.
	sg1 = Show[pg1, PlotRange ->All];
Test in the array:
	Show[GraphicsArray[{{sg1},{g2}}]]

Alternatively we can use FullOptions.
The steps are similar.
	ytks = FullOptions[g1, Ticks][[2]];
Pad the labels (a little twist is that we have to use Round to get  
integer labels)
	pytks =
	   Cases[fog1[[2]],
	  {n_,p_?NumberQ, r___} :> {n,PaddedForm[Round[p],5]}
	];
Show tha modified g1
	sog1 = Show[g1, Ticks -> {Automatic, pytks}];

Check the array
	Show[GraphicsArray[{{sog1},{g2}}]];

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: how to draw the contour lines on a surface
  • Next by Date: Re: mathematica in C
  • Previous by thread: Re: Aligning Graphs in GraphicsArray
  • Next by thread: Help on a function (or a program really)