3
$\begingroup$

I'm new to Mathematica plots. The following is a small part of my research results:

gthres = 1/3 + (19 - 3 Sqrt[33])^(1/3)/3 + (19 + 3 Sqrt[33])^(1/3)/3;
tthres = Log[gthres];
plot1 = ListLinePlot[{{0.609378, 10}, {0.609379, 8}, {0.609395, 
    6}, {0.610285, 4}, {0.61073, 3.8}, {0.611392, 3.6}, {0.612376, 
    3.4}, {0.613835, 3.2}, {0.615994, 3}, {0.619176, 2.8}, {0.62384, 
    2.6}, {0.630628, 2.4}, {0.640412, 2.2}, {0.654347, 2}, {0.663323, 
    1.9}, {0.673925, 1.8}, {0.686401, 1.7}, {0.70103, 1.6}, {0.718126,
     1.5}, {0.738047, 1.4}, {0.761207, 1.3}, {0.788093, 1.2}}, 
  PlotStyle -> Red, AxesLabel -> {t, k}];
plot2 = ListLinePlot[{{tthres, 10}, {tthres, 0}}, PlotStyle -> Dotted,
   AxesLabel -> {t, k}];
plot3 = ListLinePlot[{{0.00025, 0.001}, {0.170589, 1}, {0.261065, 
    2}, {0.317783, 3}, {0.35709, 4}, {0.386195, 5}, {0.408763, 
    6}, {0.426861, 7}, {0.44175, 8}, {0.454247, 9}, {0.464908, 
    10}, {0.482179, 12}, {0.495613, 14}, {0.511024, 17}, {0.522663, 
    20}, {0.536849, 25}, {0.546988, 30}, {0.55461, 35}, {0.560556, 
    40}, {0.565329, 45}, {0.569245, 50}}, PlotStyle -> Black, 
  AxesLabel -> {t, \[Theta]}]

The three plots above have different $x$ and $y$-axis. I'd like to combine them as one plot, with $\theta$ being the left $y$-axis, $k$ being the right $y$-axis, and $t\in(0,0.8)$ being the $x$-axis. Can anyone give me some hint or help? Thanks in advance!

$\endgroup$
4
  • $\begingroup$ tthres is not defined $\endgroup$
    – kglr
    May 22, 2023 at 16:26
  • $\begingroup$ Oh sorry, updated. $\endgroup$ May 22, 2023 at 16:28
  • $\begingroup$ CombinePlots with multiple axes $\endgroup$
    – kglr
    May 22, 2023 at 16:29
  • $\begingroup$ Yeah I was searching those CombinePlots, but I was having some problem combining different $x$ ranges together. In my case, the $x$ range of plot1 is to the right of tthres and the $x$ range of plot3 is to the left of tthres. $\endgroup$ May 22, 2023 at 16:33

1 Answer 1

6
$\begingroup$
  1. With data1 and data3 the input lists in plot1 and plot3 in OP, find the MinMax of vertical coordinates:

yminmax1 = MinMax @ data1[[All, 2]];
yminmax3 = MinMax @ data3[[All, 2]];
  1. Rescale data3 so that it has the same vertical range as data1:

data3rescaled = Transpose[{#, Rescale[#2, yminmax3, yminmax1]} & @@ 
  Transpose[data3]];
  1. Plot data1 and data3rescaled together using ListLinePlot. Use tthres as GridLines, and use Charting`FindTicks to get the ticks on the left frame to match the values in data3:

ListLinePlot[{data3rescaled, data1}, 
 GridLines -> {{tthres}, None}, 
 GridLinesStyle -> Directive[AbsoluteThickness[1], Dashed], 
 PlotStyle -> {Black, Red},
 LabelStyle -> 16, 
 ImageSize -> Large, 
 Frame -> True, 
 FrameLabel -> {{θ, k}, {t, None}}, 
 FrameTicks -> {{Charting`FindTicks[yminmax1, yminmax3],  All}, 
   {Automatic, Automatic}}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks a lot for your reply! There are two small things (which don't matter anymore though): 1. Need data1={{},{},...}, data3={{},{},...}; 2. The $k$ and $\theta$ axis need to be reversed. $\endgroup$ May 22, 2023 at 17:41
  • 1
    $\begingroup$ fixed the reversed $k$ and $\theta$ axes issue, $\endgroup$
    – kglr
    May 22, 2023 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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