3
$\begingroup$

I have a dataset as follows.

dat = {{0.9, 0.5, 0.402833, 0.307951, 0.253249, 0.213556, 0.180372, 0.147384}, {0.8, 0.5, 0.405711, 0.314656, 0.263473, 0.227789, 0.2, 0.176647}, {0.7, 0.5, 0.408, 0.319831, 0.27104, 0.23772, 0.212484, 0.192105}, {0.6, 0.5, 0.409821, 0.323862, 0.276786, 0.245031, 0.221331, 0.202523}, {0.5, 0.5, 0.411258, 0.326996, 0.281179, 0.250518, 0.227833, 0.210004}, {0.4, 0.5, 0.412369, 0.329394, 0.284501, 0.254619, 0.232633, 0.215455}, {0.3, 0.5, 0.413195, 0.331165, 0.286937, 0.257602, 0.236097, 0.219358}, {0.2, 0.5, 0.413767, 0.332384, 0.288605, 0.259634, 0.238445, 0.221989}, {0.1, 0.5, 0.414103, 0.333098, 0.289578, 0.260816, 0.239807, 0.223511}, {0.0001, 0.5, 0.414214, 0.333333, 0.289898, 0.261204, 0.240253, 0.224009}}

I would like to plot with the first column, starting with 0.9 and ending with 0.0001, on the x-axis and each of the rest of the columns on the y-axis as a separate line. I would like to add two things to the plot. The first is the name for each line: $q=1$, $q=1.5$, $q=2.5$, $q=3.5$, $q=4.5$, $q=5.5$, and $q=6.5$, respectively. Second, to highlight that each line is converging to a certain level, I would like to add a converging line as a dotted line for each line along with the corresponding converging value on the x-axis. In all, the plot I'm looking for looks something like this, which only plots three selected lines whereas my data should have six lines.

enter image description here

My code for this is:

ListPlot[dat]

And I was not able to figure out the rest of the details of the plot. Please help.

$\endgroup$

1 Answer 1

5
$\begingroup$
qValues = {1, 1.5, 6.5};

ListLinePlot[Transpose[
    {dat[[All, 1]], dat[[All, #]]}] & /@ Range[2, 4],
 ScalingFunctions -> {"Reverse", None},
 Frame -> True,
 FrameLabel -> (Style[#, 14] & /@
    {HoldForm[d], HoldForm[r]}),
 PlotLabels -> Placed[
   StringForm["q=``", #] & /@ qValues,
   After],
 PlotRange -> {Automatic, {0.125, 0.5}},
 GridLines -> {None, dat[[-1, 2 ;;]]},
 GridLinesStyle -> Directive[Darker@Gray, Dashed],
 Epilog -> {Text[
      StringForm["``(``)", 
       Superscript[HoldForm[γ], "*"], #[[1]]],
      {-0.9, #[[2]]}, {-1, -1}] & /@
    Transpose[{qValues, dat[[-1, 2 ;;]]}]},
 PlotRangeClipping -> False,
 ImagePadding -> {{50, 40}, {35, 20}},
 ImageSize -> Large]

enter image description here

EDIT: For the revised data

qValues = {1, Range[1.5, 6.5]} // Flatten;
rmin = 0.125;
rmax = 0.52;
dmin = dat[[-1, 1]];

ListLinePlot[Transpose[{dat[[All, 1]], dat[[All, #]]}] & /@
  Range[2, Length@dat[[1]]],
 ScalingFunctions -> {"Reverse", None},
 Frame -> True,
 FrameLabel -> (Style[#, 14] & /@ {HoldForm[d], HoldForm[r]}),
 PlotRange -> {Automatic, {rmin, rmax}},
 GridLines -> {{dat[[-1, 1]]}, dat[[-1, 2 ;;]]},
 GridLinesStyle -> Directive[Darker@Gray, Dashed],
 Epilog -> {Text[
      StringForm["``(``)", Superscript[HoldForm[\[Gamma]], "*"], #[[1]]],
      {-dat[[1, 1]], #[[2]]}, {-1, -1}] & /@ 
    Transpose[{qValues, dat[[-1, 2 ;;]]}],
   Text[StringForm["q=``", #[[1]]], {0, #[[2]]}, {-2.5, 0}] & /@
    Transpose[{qValues, dat[[-1, 2 ;;]]}],
   Text[StringForm["d=``", dmin], {dmin, rmin}, {1, -2}]},
 PlotRangeClipping -> False,
 ImagePadding -> {{50, 45}, {35, 20}},
 ImageSize -> Large]

enter image description here

$\endgroup$
5
  • $\begingroup$ Bob, thanks! In fact, my original data has more columns and I was trying to apply your suggested approach but I failed. So I edited the post to change the dataset by adding more columns. Now instead of three line, it should now have six lines. Can you please help once more? And would it be possible to replace 0 at one end of x-axis with 0.001? $\endgroup$
    – ppp
    Jul 5, 2023 at 3:32
  • $\begingroup$ One typo in the above comment: There should be seven lines, not six. $\endgroup$
    – ppp
    Jul 5, 2023 at 3:57
  • $\begingroup$ This is perfect, thank you so much, Bob! $\endgroup$
    – ppp
    Jul 5, 2023 at 5:29
  • $\begingroup$ May I ask? How do you make those colored solid lines thinner? $\endgroup$
    – ppp
    Sep 4, 2023 at 0:03
  • 1
    $\begingroup$ PlotStyle -> AbsoluteThickness[1] or whatever desired thickness. $\endgroup$
    – Bob Hanlon
    Sep 4, 2023 at 0:45

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.