8
$\begingroup$

I have two plots which I want to present on a single figure.

enter image description here

The bottom left corner is a point of origin of the first plot. The top right corner is a point of origin of the second plot. Also, the second plot's axes have reversed directions. That image presents those two plots - the rightmost function belongs to the second plot.

I am using Epilog->Inset[Rotate[plot2,180 Degree]]. The result I posted was obtained after tweaking ImageSize, ImagePadding, AspectRatio and Inset coordinates with some arbitrary numbers. Is there a different, perhaps more elegant way?

edit: Code snippet:

T = {{"100", 12.23, 2.675, 1}, {"140", 35.2, 3.5, 1.4}, {"180", 81.3,4.275, 1.9}, 
     {"220", 162, 5.05, 2.4}, {"260", 288, 5.8,2.9}, {"300", 451, 6.4, 3.3}, 
     {"340", 674, 7, 3.8}, {"360", 818,7.25, 4.1}, {"400", 1160, 7.825, 4.6}};

p1 = Plot[(Pi^2*205*10^9*T[[2, 2]]*10^(-8)/x^2)/1000, {x, 0, 10}, ImageSize -> 1000,
       PlotRange -> {0, 3000}, ImagePadding -> {{6, 5}, {5, 6}}, AspectRatio -> 0.595];

Show[Table[{
            Plot[(Pi^2*205*10^9*T[[n, 2]]*10^(-8)/x^2)/1000, {x, 0,T[[n,3]]},
                 PlotStyle -> {Thick}],
            Plot[(Pi^2*205*10^9*T[[n, 2]]*10^(-8)/x^2)/1000, {x, T[[n,3]],10}, 
                PlotStyle -> {Dashed}]}
         , {n, Dimensions[T][[1]]}],
     PlotRange -> {0, 3000}, GridLines -> {Range[0, 10, 1], Range[0, 3000, 100]},
     GridLinesStyle -> Directive[GrayLevel[0.7], Dashed], ImageSize -> 1000,  
     ImagePadding -> {{6, 5}, {5, 6}}, 
     Epilog -> {
        Table[Inset[Framed[T[[n, 1]], RoundingRadius -> 10, Background -> White], 
                    {T[[n, 4]], 250*T[[n, 4]]}],
             {n,Dimensions[T][[1]]}],
        Inset[Rotate[p1, 180 Degree], {5.01, 1490}]
                }
     ]
$\endgroup$
  • 1
    $\begingroup$ Hello. I always find a pice of code something extra motivating to start to work on solution :) $\endgroup$ – Kuba Jul 4 '13 at 17:15
  • $\begingroup$ I was a little hesitant, since like I said, the current solution is terribly rough and full of arbitrary numbers. $\endgroup$ – rythin Jul 4 '13 at 17:30
  • $\begingroup$ Please tell me if 1) ticks for reversed plot should be upside down? 2) what is Your main goal, maybe there is no need for so many operations. $\endgroup$ – Kuba Jul 4 '13 at 18:23
  • $\begingroup$ Thanks for the interest! 1. Nope, the whole figure should be readable from just one side. 2. My goal is to compress information from a number of figures and secondary algorithms into as little space as possible. The result will be a pocket-size guide of sorts. $\endgroup$ – rythin Jul 4 '13 at 18:48
11
$\begingroup$

Following solution is almost fully automatic, You only have to pay attention to ticks. Main idea is to use ImagePadding with Overlay. Reversed Ticks are created automatically.

T = {{"100", 12.23, 2.675, 1}, {"140", 35.2, 3.5, 1.4}, {"180", 81.3,4.275, 1.9}, 
 {"220", 162, 5.05, 2.4}, {"260", 288, 5.8,2.9}, {"300", 451, 6.4, 3.3}, 
 {"340", 674, 7, 3.8}, {"360", 818,7.25, 4.1}, {"400", 1160, 7.825, 4.6}};
f[x_, t_] := (Pi^2*205*10^9*t*10^(-8)/x^2)/1000

Edit: I have replaced first answer with a little bit clearer version with consistent ticks, the idea is the same:

Module[{ran = {{0, 10}, {0, 3000}}, ticks},
 ticks = Fold[#2 /@ #1 &, Reverse@ran,
             {FindDivisions[#, 50] &,
              {#, Flatten@Riffle[#[[;; ;; 5]], {Table["", {4}]}]} &,
              Transpose /@ {#, {#[[1]], Reverse@#[[2]]}} &}];
With[{
 options = Sequence[ImagePadding->30, ImageSize->800, AspectRatio->1, Axes->False,
                    PlotRange -> ran],
 plotopt = Sequence[PlotStyle -> {Thick, {Thick, Dashed}}, PlotRange -> ran],
 showopt = Sequence[GridLines -> {Range[0, 10, 1], Range[0, 3000, 100]}, Frame -> True, 
                FrameTicks->ticks, GridLinesStyle->Directive[GrayLevel[0.7], Dashed]]
},
Overlay[{
  Show[Plot[{If[x<#3, f[x,#2]], If[x>#3, f[x,#2]]}, {x,ran[[1,1]], ran[[1,2]]}, 
            plotopt] & @@@T,
       options, showopt],
  Rotate[#, Pi] &@Plot[f[x, T[[2, 2]]], {x, 0, 10}, options, PlotStyle -> Thick]
       }]
    ]
]

enter image description here

Since ImagePadding does not care about FrameLabels etc. one can simply add those to showopt (larger ImagePadding required in order to include them). Also AspectRatio can be modyfied with no harm:

enter image description here

$\endgroup$
  • $\begingroup$ This is brilliant, thanks a dozen! Your rework is a hundred times more elegant and readable than mine. I greatly appreciate your help. Dzieki! $\endgroup$ – rythin Jul 4 '13 at 22:40
  • $\begingroup$ @rythin I'm glad You like it. Take a look at remark I've added. I have also corrected small mistake in the code, reversed plot was without proper PlotRange, now it is good. $\endgroup$ – Kuba Jul 5 '13 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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