Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: TwoAxisListPlot for V6?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83894] Re: TwoAxisListPlot for V6?
  • From: dh <dh at metrohm.ch>
  • Date: Mon, 3 Dec 2007 07:14:31 -0500 (EST)
  • References: <fim8ib$raq$1@smc.vnet.net>


Hi Jerry,

I tried to make quick rework of the TwoAxes plot.

hope this helps, Daniel



=========================================================

(*Create plots with 2 axes right and left*)



(* ListPlot of 2 datasets

Input: f,g: data lists: {yi,..} or {{xi,yi},..}

        frange, grange: {min,max} y-range of list to plot, if not 

specified or {0,0}= full dta range

*)

TwoAxisListPlot[{f_List,g_List},frange_:{0,0},grange_:{0,0},opts___?OptionQ]:=Module[{old,new,scale,fm,fM,gm,gM,newg},

{fm,fM}=If[frange=={0,0},{Min[#],Max[#]}& @ 

If[VectorQ[First[f]],f[[All,2]],f],frange];

{gm,gM}=If[grange=={0,0},{Min[#],Max[#]}& @ 

If[VectorQ[First[g]],g[[All,2]],g],grange];

scale[var_]=((var-gm)*(fM-fm))/(gM-gm)+fm;

old=AbsoluteOptions[ListPlot[g,Frame->True,PlotRange->{gm,gM},DisplayFunction->Identity],FrameTicks][[1,2,2]];

new=(Prepend[Rest[#1],scale[First[#1]]]&)/@old;

newg=Transpose[{Transpose[g][[1]],Map[scale,Transpose[g][[2]],{1,2}]}];

ListPlot[{f,newg},Frame->True,FrameTicks->{Automatic,Automatic,None,new},PlotStyle->{{RGBColor[1,0,0]},{RGBColor[0,0,1]}},FrameStyle->{{},{RGBColor[1,0,0]},{},{RGBColor[0,0,1]}},PlotRange->{fm,fM}+.05 

(fM-fm),opts]]



(* Plot of 2 function

Input: f,g: data function to plot

        {x,min,max}: variable used in f and g and plot range

        frange, grange: {min,max} y-range of list to plot, if not 

specified or {0,0}= full y range

*)



TwoAxisPlot[{f_,g_},{x_,min_,max_},frange_:{0,0},grange_:{0,0},(opts___)?OptionQ]:=Module[{old,new,scale,pts,gstuff,fstuff,fm,fM,gm,gM},

{fm,fM}=If[frange=={0,0},{Min[#],Max[#]}& @ 

Table[f,{x,min,max,(max-min)/100}],frange];

{gm,gM}=If[grange=={0,0},{Min[#],Max[#]}& @ 

Table[g,{x,min,max,(max-min)/100}],grange];Print[{{fm,fM},{gm,gM}}];

scale[var_]=((var-gm)*(fM-fm))/(gM-gm)+fm;

old=AbsoluteOptions[Plot[g,{x,min,max},Frame->True,DisplayFunction->Identity,PlotRange->{gm,gM}],FrameTicks][[1,2,2]];

new=(Prepend[Rest[#1],scale[First[#1]]]&)/@old;

Plot[{f,scale[g]},{x,min,max},Frame->True,PlotRange->{fm,fM}+{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]]



===================================================================================



Jerry wrote:

> Hello gurus, I'm trying to get more of my old V5 routines 

> working in V6. I had been using TwoAxisListPlot described here:

> 

> http://support.wolfram.com/mathematica/graphics/2d/twoaxisgraph.html

> 

> HELP tells me MultipleListPlot is obsolete and to use 

> ListPlot instead. So I made that change in the code (along 

> with not loading MultipleListPlot) and I still get lot's of 

> errors. I'm using the example data1, data2 given in the link 

> above.

> 

> Note the only other change I made was to change SymbolStyle 

> to PlotStyle, that seemed to get rid of many error messages.

> 

> The remaining errors say

> "Options expected (instead of {{27,5.0402},{28,.....<snip>"

> 

> Can someone please help me get this example working? Thanks.

> 




  • Prev by Date: Re: plotting vectors
  • Next by Date: Re: Hiding number cell
  • Previous by thread: Re: Re: different eigenvectors
  • Next by thread: Re: TwoAxisListPlot for V6?