MathGroup Archive 2004

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

Search the Archive

Difference in Plots in Mathematica v4.0 and v5.0

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50571] Difference in Plots in Mathematica v4.0 and v5.0
  • From: "Gaurav Mendiratta" <gauravm at seas.upenn.edu>
  • Date: Fri, 10 Sep 2004 04:06:36 -0400 (EDT)
  • Organization: University of Pennsylvania
  • Sender: owner-wri-mathgroup at wolfram.com


 Hi,
I have a code(PlotGenome) which draws perfect plots in Mathematica .4.0,
but  a part of the plot is cut off (mostly the leftmost) in Mathematica
v5.0. Below is the code. any suggestions , on how can I correct the problem?
Thanks
 Gaurav

 drawtext[s_, {x_,y_}, align_, opts___] :=
 (xmin = Min[xmin, x]; xmax = Max[xmax, x];
 ymin = Min[ymin, y]; ymax = Max[ymax, x];
 Text[s, {x,y}, align, opts])

 buildtree[{f_Real, t_}, h_, _, x_, y_, g_, n_, offset_, opts___] :=
 {drawtext[NumberForm[f, n], {x, y} + offset[{0, -h(g/2)}], offset[{0, -2h
 g}], opts]}

 buildtree[{f_, t_}, h_, _, x_, y_, g_, n_, offset_, opts___] :=
 {drawtext[f, {x, y} + offset[{0, -h(g/2)}], offset[{0, -h g}], opts]}

 buildtree[{f_, t_, {args___}}, h_, w_, x_, y_, g_, n_, offset_, opts___] :=
 Module[{nx, ny, nw},
 nw = w/Length[{args}];
 {nx, ny} = {x, y} + offset[{-w/2 - nw/2, h}];
 Flatten[{Map[{Line[{{x, y}, AddTo[{nx, ny}, offset[{nw, 0}]] + offset[{0, -g h}]}],
 buildtree[#, h, nw, nx, ny, g, n, offset, opts]}&, {args}],
 drawtext[f, {x, y} + offset[{0, -h(g/2)}], {0,0}, opts]}]]

 PlotGenome::orient = "Only \"Horizontal\" and \"Vertical\" are valid values
 of option TreeOrientation.";
 PlotGenome::root = "Option RootPosition -> `` does not evaluate to either 1 or -1.";
 PlotGenome::precision = "Option NodePrecision -> `` does not evaluate to a
 positive integer.";
 PlotGenome::space = "Option NodeSpacing -> `` does not evaluate to a number
 between 0 and 1.";

 Options[PlotGenome] = {TreeOrientation -> "Vertical", RootPosition -> 1,
 TextStyle -> {FontFamily -> "Ariel", FontWeight -> "Bold", FontSize -> 10},
 NodeBackground -> Automatic, NodePrecision -> 2, NodeSpacing -> 0,
 NodeSubstitutions -> {GreaterEqual -> "\[GreaterEqual]", Greater -> ">",
 LessEqual -> "\[LessEqual]", Less -> "<", Times -> "×", Divide -> "÷",
 Plus -> "+", Subtract -> "-"}};

 PlotGenome[Genome[{f_, t_}], opts___?OptionQ] :=
 PlotGenome[Genome[{f, t, {noArguments}}], opts]

 PlotGenome[Genome[{f_, t_, {args___}}], opts___?OptionQ] :=
 Module[{$RecursionLimit = Infinity},
 Module[{orient, offset, root, style, subst, color, genome, h, g, n,
 gropts, txtopts, tree, s=0.05},
 If[!checkoptions[PlotGenome::badopt, Join[Options[PlotGenome],
 Options[Graphics]], opts], Return[$Failed]];

 orient = TreeOrientation /. {opts} /. Options[PlotGenome];
 Switch[orient,
 "Vertical", offset = Identity,
 "Horizontal", offset = Reverse,
 _, Message[PlotGenome::orient, orient]; Return[$Failed]];

 root = RootPosition /. {opts} /. Options[PlotGenome];
 If[(root != 1) && (root != -1),
 Message[PlotGenome::root, root]; Return[$Failed]];
 h = root*First[offset[{-1, 1}]];

 style = TextStyle /. {opts} /. Options[PlotGenome];
 color = NodeBackground /. {opts} /. Options[PlotGenome];
 subst = NodeSubstitutions /. {opts} /. Options[PlotGenome];

 g = NodeSpacing /. {opts} /. Options[PlotGenome];
 If[Not[((Head[g] == Real) || (Head[g] == Integer)) && (g >= 0) && (g <)],
 Message[PlotGenome::space, g]; Return[$Failed]];

 n = NodePrecision /. {opts} /. Options[PlotGenome];
 If[Not[(Head[n] == Integer) && (n > 0)],
 Message[PlotGenome::precision, n]; Return[$Failed]];

 gropts = filteroptions[Graphics, opts];
 txtopts = Sequence @@ {Background -> color, filteroptions[Text, opts]};

 genome = If[args === noArguments, {f, t}, {f, t, {args}}] /. subst;

 xmin = xmax = ymin = ymax = 0;

 tree = buildtree[genome, h, 1, 0, 0, g, n, offset, txtopts];

 Show[Graphics[tree], TextStyle -> style, gropts, PlotRegion ->
 {{s,1-s},{s,1-s}}]]]


  • Prev by Date: Example Problems
  • Next by Date: Re: Plotting an implicit function
  • Previous by thread: Re: Table of Contents in Publicon?
  • Next by thread: DSolve Question