Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: How can I create a two-axis graph in Mathematica v6

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91745] Re: How can I create a two-axis graph in Mathematica v6
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sun, 7 Sep 2008 05:34:45 -0400 (EDT)
  • References: <g9t6of$ja8$1@smc.vnet.net>

Hi,

somthing is mix up the Mathematica parser and if you transform the
Input Cell of TwoAxisPlot[] into the InputForm[]
the result is

TwoAxisPlot[{f_, g_}, {x_, x0_, x1_}, opts : OptionsPattern[]] :=
  Module[{f0, f1, g0, g1, gp, scale, gticks},
      ({f0, f1} =
       Options[Plot[f, {x, x0, x1}, Frame -> True, opts],
         PlotRange][[1, 2, 2]]; )*
        ({g0, g1} =
       Options[gp = Plot[g, {x, x0, x1}, Frame -> True, opts],
         PlotRange][[1, 2, 2]]; )*
        (scale[y_] := f0 + ((f1 - f0)*(y - g0))/(g1 - g0); )*
        (gticks =
       Apply[{scale[#1], ##2} & ,
        AbsoluteOptions[gp, FrameTicks][[1, 2, 2]], {1}]; )*
        Plot[{f, scale[g]}, {x, x0, x1}, PlotRange -> 1.001*{f0, f1},
     Frame -> True,
          FrameTicks -> {{Automatic, gticks}, {Automatic,
        Automatic}},
          FrameStyle -> {{defaultColor[1],
        defaultColor[2]}, {{}, {}}}, opts]]

notice the (__)* at the line ends. Try

TwoAxisPlot[{f_, g_}, {x_, x0_, x1_}, opts : OptionsPattern[]] :=
  Module[{f0, f1, g0, g1, gp, scale, gticks},
      {f0, f1} =
    Options[Plot[f, {x, x0, x1}, Frame -> True, opts], PlotRange][[1,
      2, 2]];
       {g0, g1} =
    Options[gp = Plot[g, {x, x0, x1}, Frame -> True, opts],
      PlotRange][[1, 2, 2]];
       scale[y_] := f0 + ((f1 - f0)*(y - g0))/(g1 - g0);
       gticks =
    Apply[{scale[#1], ##2} & ,
     AbsoluteOptions[gp, FrameTicks][[1, 2, 2]], {1}];
       Plot[{f, scale[g]}, {x, x0, x1}, PlotRange -> 1.001*{f0, f1},
    Frame -> True,
         FrameTicks -> {{Automatic, gticks}, {Automatic, Automatic}},
         FrameStyle -> {{defaultColor[1], defaultColor[2]}, {{}, {}}},
    opts]]

and all work as expected.

Regards
   Jens


avteran1 at gmail.com wrote:
> Hello All,
> 
> In my efforts to create a two-axis graph in Mathematica v6. I came
> across a Mathematica Technical Support FAQ titled "Can I create a two-
> axis graph in Mathematica?" There are two versions of this FAQ the
> most recent and updated version of the FAQ can be found at the
> following URL:
> 
> http://support.wolfram.com/mathematica/graphics/combine/twoaxisgraph.en.html
> 
> The URL site provides a Mathematica notebook titled "twoaxisgraph.en"
> which may be downloaded.
> 
> I have downloaded the "twoaxisgraph.en" notebook and have tried to use
> it for my application but I continue to have problems with this code.
> Without making any changes to the downloaded notebook and when
> evaluating the part of the notebook that is for Mathematica 6.0 and
> later, I do not get the same output plot as originally displayed in
> the downloaded notebook. Specifically I am referring to the output
> plots Out[4], Out[5], Out[7], and Out[8] that appear in the first part
> of the web page. Instead, the output has "Null^4" preceding the plot
> and the image size of the output plot is small and must be resized
> manually to be able to be viewed.
> 
> This is one problem with the part of the notebook dealing with
> "Working with Continuous Plots" with "Mathematica 6.0 and Later." The
> second problem is that it seems this code does not entirely do what I
> need it to do.
> 
> Ideally I would like to have something similar to the TwoAxisPlot
> command that is used in the section "Working with Continuous Plots"
> for "Mathematica Versions Prior to 6.0." That version allows you to
> specify the common "x-range" to both plots and choose the "y-ranges"
> for each individual plot to be plotted. This way you can see both
> plots in their entirety regardless if one plots range is many times
> larger than the others. Please refer to both the input and output
> graphics of the last section of the web page, specifically In[2],
> In[3], Out[2], and Out[3].
> 
> I need help with either making the code for "Working with Continuous
> Plots" with "Mathematica 6.0 and Later" do what the code for "Working
> with Continuous Plots" with "Mathematica Versions Prior to 6.0" does,
> or change the code in "Working with Continuous Plots" with
> "Mathematica Versions Prior to 6.0" so that it will work in
> Mathematica v6. (Please refer to the URL)
> 
> I am not very knowledgeable in Mathematica programming so any
> assistance with this matter would be greatly appreciated. Any
> suggestions or insight on how to change this notebook code to apply to
> my needs would also help. As a reminder I am using Mathematica
> v6.0.2.0.
> 
> Thank you,
> Tony
> 


  • Prev by Date: Re: Points on a ContourPlot
  • Next by Date: Re: question about Solve
  • Previous by thread: Re: How can I create a two-axis graph in Mathematica v6
  • Next by thread: Re: genetic algorithms