3
$\begingroup$

Possible Duplicate:
1 Plot, 2 Scale/Axis

I aim to combine two plots in which the YY axes have different scales: one goes PlotRange->{0,100} while the other goes PlotRange->{0,2.5*^-5}. I've been trying to do this for several hours and, although I think I'm almost there, I cant seem to make it.

Here's the input code:

(*not very important, is one of the functions to be plotted*)
P[st_, base_, int_] :=
 Module[{nper, period, length, tcap, tarteriols, tvenuls, ttotaloxi},
  period = 60/((4/3 Pi (0.1/2)^3)/48);
  length = 2;
  nper = (t - st)/period;
  If[0 <= (t - st) - period Floor@nper < length, base + int, base]
  ]

The problem is in this one for sure:

Combineplots[{hout_, maxrange_}, {t_, t0_, tf_}] :=
     Module[{relgraf, ihgraf, relrange, ih2o2range, relticks, 
       ih2o2ticks},
      relgraf = 
       Plot[Evaluate[{10 t} /. setpars /. pa[h2o2out]], {t, t0, tf},
        LabelStyle -> {FontFamily -> "Arial", Bold, 40},
        PlotStyle -> {{Thickness[0.011], 
           Darker[Green, 0.5]}, {Thickness[0.011], 
           Darker[Red, 0.2]}, {Thickness[0.007], 
           Darker[Blue, 0.3]}, {Thickness[0.007], Darker[Orange, 0.3]}}];


  ih2o2graf = 
   Plot[Pulse[2, 1*^-9, h2o2out], {t, t0, tf}, 
    LabelStyle -> {FontFamily -> "Arial", Bold, 40},
    PlotStyle -> {Thickness[0.007], Black}];
  relrange = ({0, 100});
  ih2o2range = ({0, maxrange});

  Show[relgraf, 
   ih2o2graf /. 
    Graphics[graf_, s___] :> 
     Graphics[
      GeometricTransformation[graf, 
       RescalingTransform[{{0, 10}, ih2o2range}, {{0, 10}, 
         relrange}]], s], Axes -> True,

   Frame -> {{True, True}, {True, False}},
   FrameStyle -> AbsoluteThickness[3],
   FrameTicks -> {{Automatic, {{1/200000, "5"}, {1/100000, "10"}, {3/
        200000, "15"}, {1/50000, "20"}, {1/40000, "25"}, {3/100000, 
        "30"}}}, {Automatic, None}}, ImageSize -> Medium]]
Combineplots[{2*^-5, 3*^-5}, {t, 0, 10}]

I've been able to plot both together correctly, with exception for the right YY axis: enter image description here

Yet, the ticks theoretically are placed at the correct place (using the same tick marks in a single plot I get the correct marking:) enter image description here

Do you guys think you can give me some clue please? Thanks so much!

$\endgroup$
  • $\begingroup$ thanks! already looking into it! and I'm sorry if this seems like repeating the same question as the one in the link :S EDIT: indeed, I also tried with Overlayand gives almost the same result with many less code lines than the ones I was using. Superimposition of both graphs isn't perfect yet, but a bit of fine tuning and it works too. Problably playing around with ImagePadding and thats it! thanks again! $\endgroup$ – Sosi Jun 1 '12 at 10:36
5
$\begingroup$

You rescaled the plot, but you didn't adjusted the position of the tick marks of the right vertical axis. To correct this you could do something like this:

Combineplots[{hout_, maxrange_}, {t_, t0_, tf_}] := 
 Module[{relgraf, ihgraf, relrange, ih2o2range, relticks, ih2o2ticks, newticks}, 
  relgraf = Plot[Evaluate[{10 t}], {t, t0, tf}, 
    LabelStyle -> {FontFamily -> "Arial", Bold, 40}, 
    PlotStyle -> {{Thickness[0.011], 
       Darker[Green, 0.5]}, {Thickness[0.011], 
       Darker[Red, 0.2]}, {Thickness[0.007], 
       Darker[Blue, 0.3]}, {Thickness[0.007], Darker[Orange, 0.3]}}];

  ih2o2graf = Plot[Pulse[2, 1*^-9, maxrange], {t, t0, tf}, 
    LabelStyle -> {FontFamily -> "Arial", Bold, 40}, 
    PlotStyle -> {Thickness[0.007], Black}];
  relrange = ({0, 100});
  ih2o2range = ({0, maxrange});
  newticks = Transpose[{Rescale[Range[6]/200000, ih2o2range, relrange], Range[6] 5}]; 
  Show[relgraf, 
   ih2o2graf /. Graphics[graf_, s___] :> 
     Graphics[GeometricTransformation[graf, 
       RescalingTransform[{{0, 10}, ih2o2range}, {{0, 10}, relrange}]], s], 
   Axes -> True, 
   Frame -> {{True, True}, {True, False}}, 
   FrameStyle -> AbsoluteThickness[3], 
   FrameTicks -> {{Automatic, newticks}, {Automatic, None}}, 
   ImageSize -> Medium]]

Combineplots[{2*^-5, 3*^-5}, {t, 0, 10}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Oh, thanks! Indeed, it was something so simple and I wasn't seeing it. Thanks! $\endgroup$ – Sosi Jun 1 '12 at 10:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.