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: [mg91773] Re: How can I create a two-axis graph in Mathematica v6
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 7 Sep 2008 05:40:06 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g9t6of$ja8$1@smc.vnet.net>

avteran1 at gmail.com wrote:

> 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.

Works fine on my system. Note that you must *not* load the 
packageGraphics`MultipleListPlot` when working with version 6.x.

In[1]:= $Version
TwoAxisPlot[{f_, g_}, {x_, min_, max_}, frange_,
grange_, (opts___)?OptionQ] :=
Module[{old, new, scale, pts, gstuff, fstuff}, {fm, fM} = frange;
{gm, gM} = grange;
scale[var_] = ((var - gm)*(fM - fm))/(gM - gm) + fm;
old = AbsoluteOptions[
Plot[g, {x, min, max}, Frame -> True, PlotRange -> grange,
DisplayFunction -> Identity], FrameTicks][[1, 2, 2]];
new = (Prepend[Rest[#1], scale[First[#1]]] &) /@ old;
Plot[{f, scale[g]}, {x, min, max}, Frame -> True,
PlotRange -> frange + {0, .05 (fM - fm)},
FrameTicks -> {Automatic, Automatic, None, new},
PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 0, 1]}},
FrameStyle -> {{}, {RGBColor[1, 0, 0]}, {}, {RGBColor[0, 0, 1]}},
opts]]
TwoAxisPlot[{x^3, Sqrt[x]}, {x, 0, 4}, {0, 64}, {0, 2}]
TwoAxisPlot[{Sqrt[x], x^3}, {x, 0, 4}, {0, 2}, {0, 70}]

Out[1]= "6.0 for Mac OS X x86 (64-bit) (May 21, 2008)"

[... graphics deleted ...]

Regards,
-- Jean-Marc



  • Prev by Date: Re: Thinking Mathematica: Any suggestions?
  • Next by Date: Re: How can I create a two-axis graph in Mathematica v6
  • Previous by thread: How can I create a two-axis graph in Mathematica v6
  • Next by thread: Re: How can I create a two-axis graph in Mathematica v6