5
$\begingroup$

Consider my data (sorry for long code but it's necessary):

data = {{{-(4963/20), 3.58534}, {-(4463/20), 3.62705}, {-(3963/20), 
   3.67089}, {-(3463/20), 3.71615}, {-(2963/20), 
   3.76244}, {-(2463/20), 3.80958}, {-(1963/20), 
   3.85741}, {-(1463/20), 3.90581}, {-(963/20), 3.95473}, {-(463/20), 
   4.00413}, {37/20, 4.05393}, {537/20, 4.10414}, {1037/20, 
   4.15465}, {1537/20, 4.20552}, {2037/20, 4.25667}, {2537/20, 
   4.30809}, {3037/20, 4.35981}, {3537/20, 4.41175}, {4037/20, 
   4.46395}, {4537/20, 4.51638}, {5037/20, 4.56903}, {5537/20, 
   4.62187}, {6037/20, 4.67495}, {6537/20, 4.72819}, {7037/20, 
   4.78165}, {7537/20, 4.83527}, {8037/20, 4.88908}, {8537/20, 
   4.94304}, {9037/20, 4.99718}, {9537/20, 5.05149}, {10037/20, 
   5.10595}, {10537/20, 5.16057}, {11037/20, 5.21533}, {11537/20, 
   5.27023}, {12037/20, 5.32528}, {12537/20, 5.38047}, {13037/20, 
   5.4358}, {13537/20, 5.49125}, {14037/20, 5.54682}, {14537/20, 
   5.60254}}, {{-(4963/20), 4.73311}, {-(4463/20), 
   4.69141}, {-(3963/20), 4.64757}, {-(3463/20), 4.6023}, {-(2963/20),
    4.55601}, {-(2463/20), 4.50887}, {-(1963/20), 
   4.46104}, {-(1463/20), 4.41264}, {-(963/20), 4.36372}, {-(463/20), 
   4.31432}, {37/20, 4.26452}, {537/20, 4.21432}, {1037/20, 
   4.1638}, {1537/20, 4.11294}, {2037/20, 4.06178}, {2537/20, 
   4.01037}, {3037/20, 3.95864}, {3537/20, 3.90671}, {4037/20, 
   3.85451}, {4537/20, 3.80207}, {5037/20, 3.74942}, {5537/20, 
   3.69658}, {6037/20, 3.64351}, {6537/20, 3.59026}, {7037/20, 
   3.53681}, {7537/20, 3.48318}, {8037/20, 3.42937}, {8537/20, 
   3.37542}, {9037/20, 3.32127}, {9537/20, 3.26696}, {10037/20, 
   3.21251}, {10537/20, 3.15789}, {11037/20, 3.10312}, {11537/20, 
   3.04822}, {12037/20, 2.99317}, {12537/20, 2.93798}, {13037/20, 
   2.88265}, {13537/20, 2.8272}, {14037/20, 2.77163}, {14537/20, 
   2.71592}}, {{-(4963/20), 2.07276}, {-(4463/20), 
   2.07276}, {-(3963/20), 2.07276}, {-(3463/20), 
   2.07276}, {-(2963/20), 2.07276}, {-(2463/20), 
   2.07276}, {-(1963/20), 2.07276}, {-(1463/20), 2.07276}, {-(963/20),
    2.07276}, {-(463/20), 2.07276}, {37/20, 2.07276}, {537/20, 
   2.07276}, {1037/20, 2.07276}, {1537/20, 2.07276}, {2037/20, 
   2.07276}, {2537/20, 2.07276}, {3037/20, 2.07276}, {3537/20, 
   2.07276}, {4037/20, 2.07276}, {4537/20, 2.07276}, {5037/20, 
   2.07276}, {5537/20, 2.07276}, {6037/20, 2.07276}, {6537/20, 
   2.07276}, {7037/20, 2.07276}, {7537/20, 2.07276}, {8037/20, 
   2.07276}, {8537/20, 2.07276}, {9037/20, 2.07276}, {9537/20, 
   2.07276}, {10037/20, 2.07276}, {10537/20, 2.07276}, {11037/20, 
   2.07276}, {11537/20, 2.07276}, {12037/20, 2.07276}, {12537/20, 
   2.07276}, {13037/20, 2.07276}, {13537/20, 2.07276}, {14037/20, 
   2.07276}, {14537/20, 2.07276}}, {{-(4963/20), 
   1.71283}, {-(4463/20), 1.71283}, {-(3963/20), 
   1.71283}, {-(3463/20), 1.71283}, {-(2963/20), 
   1.71283}, {-(2463/20), 1.71283}, {-(1963/20), 
   1.71283}, {-(1463/20), 1.71283}, {-(963/20), 1.71283}, {-(463/20), 
   1.71283}, {37/20, 1.71283}, {537/20, 1.71283}, {1037/20, 
   1.71283}, {1537/20, 1.71283}, {2037/20, 1.71283}, {2537/20, 
   1.71283}, {3037/20, 1.71283}, {3537/20, 1.71283}, {4037/20, 
   1.71283}, {4537/20, 1.71283}, {5037/20, 1.71283}, {5537/20, 
   1.71283}, {6037/20, 1.71283}, {6537/20, 1.71283}, {7037/20, 
   1.71283}, {7537/20, 1.71283}, {8037/20, 1.71283}, {8537/20, 
   1.71283}, {9037/20, 1.71283}, {9537/20, 1.71283}, {10037/20, 
   1.71283}, {10537/20, 1.71283}, {11037/20, 1.71283}, {11537/20, 
   1.71283}, {12037/20, 1.71283}, {12537/20, 1.71283}, {13037/20, 
   1.71283}, {13537/20, 1.71283}, {14037/20, 1.71283}, {14537/20, 
   1.71283}}, {{-(4963/20), 1.67639}, {-(4463/20), 
   1.67639}, {-(3963/20), 1.67639}, {-(3463/20), 
   1.67639}, {-(2963/20), 1.67639}, {-(2463/20), 
   1.67639}, {-(1963/20), 1.67639}, {-(1463/20), 1.67639}, {-(963/20),
    1.67639}, {-(463/20), 1.67639}, {37/20, 1.67639}, {537/20, 
   1.67639}, {1037/20, 1.67639}, {1537/20, 1.67639}, {2037/20, 
   1.67639}, {2537/20, 1.67639}, {3037/20, 1.67639}, {3537/20, 
   1.67639}, {4037/20, 1.67639}, {4537/20, 1.67639}, {5037/20, 
   1.67639}, {5537/20, 1.67639}, {6037/20, 1.67639}, {6537/20, 
   1.67639}, {7037/20, 1.67639}, {7537/20, 1.67639}, {8037/20, 
   1.67639}, {8537/20, 1.67639}, {9037/20, 1.67639}, {9537/20, 
   1.67639}, {10037/20, 1.67639}, {10537/20, 1.67639}, {11037/20, 
   1.67639}, {11537/20, 1.67639}, {12037/20, 1.67639}, {12537/20, 
   1.67639}, {13037/20, 1.67639}, {13537/20, 1.67639}, {14037/20, 
   1.67639}, {14537/20, 1.67639}}, {{-(4963/20), 
   1.62463}, {-(4463/20), 1.63505}, {-(3963/20), 
   1.64601}, {-(3463/20), 1.65733}, {-(2963/20), 1.6689}, {-(2463/20),
    1.68069}, {-(1963/20), 1.69264}, {-(1463/20), 
   1.70474}, {-(963/20), 1.71698}, {-(463/20), 1.72932}, {37/20, 
   1.74177}, {537/20, 1.75433}, {1037/20, 1.76695}, {1537/20, 
   1.77967}, {2037/20, 1.79246}, {2537/20, 1.80531}, {3037/20, 
   1.81824}, {3537/20, 1.83123}, {4037/20, 1.84428}, {4537/20, 
   1.85739}, {5037/20, 1.87055}, {5537/20, 1.88376}, {6037/20, 
   1.89703}, {6537/20, 1.91034}, {7037/20, 1.9237}, {7537/20, 
   1.93711}, {8037/20, 1.95056}, {8537/20, 1.96405}, {9037/20, 
   1.97759}, {9537/20, 1.99117}, {10037/20, 2.00478}, {10537/20, 
   2.01843}, {11037/20, 2.03212}, {11537/20, 2.04585}, {12037/20, 
   2.05961}, {12537/20, 2.07341}, {13037/20, 2.08724}, {13537/20, 
   2.10111}, {14037/20, 2.115}, {14537/20, 2.12893}}, {{-(4963/20), 
   1.61898}, {-(4463/20), 1.6294}, {-(3963/20), 1.64036}, {-(3463/20),
    1.65168}, {-(2963/20), 1.66325}, {-(2463/20), 
   1.67504}, {-(1963/20), 1.687}, {-(1463/20), 1.6991}, {-(963/20), 
   1.71133}, {-(463/20), 1.72367}, {37/20, 1.73613}, {537/20, 
   1.74868}, {1037/20, 1.7613}, {1537/20, 1.77402}, {2037/20, 
   1.78681}, {2537/20, 1.79966}, {3037/20, 1.81259}, {3537/20, 
   1.82558}, {4037/20, 1.83863}, {4537/20, 1.85174}, {5037/20, 
   1.8649}, {5537/20, 1.87811}, {6037/20, 1.89138}, {6537/20, 
   1.90469}, {7037/20, 1.91805}, {7537/20, 1.93146}, {8037/20, 
   1.94491}, {8537/20, 1.9584}, {9037/20, 1.97194}, {9537/20, 
   1.98552}, {10037/20, 1.99913}, {10537/20, 2.01278}, {11037/20, 
   2.02647}, {11537/20, 2.0402}, {12037/20, 2.05396}, {12537/20, 
   2.06776}, {13037/20, 2.08159}, {13537/20, 2.09546}, {14037/20, 
   2.10935}, {14537/20, 2.12328}}, {{-(4963/20), 
   1.82555}, {-(4463/20), 1.83076}, {-(3963/20), 
   1.83624}, {-(3463/20), 1.8419}, {-(2963/20), 1.84769}, {-(2463/20),
    1.85358}, {-(1963/20), 1.85956}, {-(1463/20), 
   1.86561}, {-(963/20), 1.87172}, {-(463/20), 1.8779}, {37/20, 
   1.88412}, {537/20, 1.8904}, {1037/20, 1.89671}, {1537/20, 
   1.90307}, {2037/20, 1.90947}, {2537/20, 1.91589}, {3037/20, 
   1.92236}, {3537/20, 1.92885}, {4037/20, 1.93538}, {4537/20, 
   1.94193}, {5037/20, 1.94851}, {5537/20, 1.95512}, {6037/20, 
   1.96175}, {6537/20, 1.96841}, {7037/20, 1.97509}, {7537/20, 
   1.98179}, {8037/20, 1.98852}, {8537/20, 1.99526}, {9037/20, 
   2.00203}, {9537/20, 2.00882}, {10037/20, 2.01563}, {10537/20, 
   2.02245}, {11037/20, 2.0293}, {11537/20, 2.03616}, {12037/20, 
   2.04304}, {12537/20, 2.04994}, {13037/20, 2.05686}, {13537/20, 
   2.06379}, {14037/20, 2.07073}, {14537/20, 2.0777}}, {{-(4963/20), 
   1.74864}, {-(4463/20), 1.75386}, {-(3963/20), 
   1.75934}, {-(3463/20), 1.76499}, {-(2963/20), 
   1.77078}, {-(2463/20), 1.77667}, {-(1963/20), 
   1.78265}, {-(1463/20), 1.7887}, {-(963/20), 1.79482}, {-(463/20), 
   1.80099}, {37/20, 1.80722}, {537/20, 1.81349}, {1037/20, 
   1.81981}, {1537/20, 1.82617}, {2037/20, 1.83256}, {2537/20, 
   1.83899}, {3037/20, 1.84545}, {3537/20, 1.85194}, {4037/20, 
   1.85847}, {4537/20, 1.86502}, {5037/20, 1.8716}, {5537/20, 
   1.87821}, {6037/20, 1.88484}, {6537/20, 1.8915}, {7037/20, 
   1.89818}, {7537/20, 1.90488}, {8037/20, 1.91161}, {8537/20, 
   1.91836}, {9037/20, 1.92512}, {9537/20, 1.93191}, {10037/20, 
   1.93872}, {10537/20, 1.94555}, {11037/20, 1.95239}, {11537/20, 
   1.95926}, {12037/20, 1.96614}, {12537/20, 1.97303}, {13037/20, 
   1.97995}, {13537/20, 1.98688}, {14037/20, 1.99383}, {14537/20, 
   2.00079}}, {{-(4963/20), 1.73374}, {-(4463/20), 
   1.73896}, {-(3963/20), 1.74444}, {-(3463/20), 1.7501}, {-(2963/20),
    1.75588}, {-(2463/20), 1.76177}, {-(1963/20), 
   1.76775}, {-(1463/20), 1.7738}, {-(963/20), 1.77992}, {-(463/20), 
   1.78609}, {37/20, 1.79232}, {537/20, 1.79859}, {1037/20, 
   1.80491}, {1537/20, 1.81127}, {2037/20, 1.81766}, {2537/20, 
   1.82409}, {3037/20, 1.83055}, {3537/20, 1.83705}, {4037/20, 
   1.84357}, {4537/20, 1.85012}, {5037/20, 1.85671}, {5537/20, 
   1.86331}, {6037/20, 1.86995}, {6537/20, 1.8766}, {7037/20, 
   1.88328}, {7537/20, 1.88999}, {8037/20, 1.89671}, {8537/20, 
   1.90346}, {9037/20, 1.91022}, {9537/20, 1.91701}, {10037/20, 
   1.92382}, {10537/20, 1.93065}, {11037/20, 1.93749}, {11537/20, 
   1.94436}, {12037/20, 1.95124}, {12537/20, 1.95814}, {13037/20, 
   1.96505}, {13537/20, 1.97198}, {14037/20, 1.97893}, {14537/20, 
   1.98589}}, {{-(4963/20), 1.75651}, {-(4463/20), 
   1.76172}, {-(3963/20), 1.7672}, {-(3463/20), 1.77286}, {-(2963/20),
    1.77864}, {-(2463/20), 1.78454}, {-(1963/20), 
   1.79052}, {-(1463/20), 1.79656}, {-(963/20), 1.80268}, {-(463/20), 
   1.80885}, {37/20, 1.81508}, {537/20, 1.82136}, {1037/20, 
   1.82767}, {1537/20, 1.83403}, {2037/20, 1.84042}, {2537/20, 
   1.84685}, {3037/20, 1.85331}, {3537/20, 1.85981}, {4037/20, 
   1.86633}, {4537/20, 1.87289}, {5037/20, 1.87947}, {5537/20, 
   1.88607}, {6037/20, 1.89271}, {6537/20, 1.89936}, {7037/20, 
   1.90604}, {7537/20, 1.91275}, {8037/20, 1.91947}, {8537/20, 
   1.92622}, {9037/20, 1.93299}, {9537/20, 1.93978}, {10037/20, 
   1.94658}, {10537/20, 1.95341}, {11037/20, 1.96025}, {11537/20, 
   1.96712}, {12037/20, 1.974}, {12537/20, 1.9809}, {13037/20, 
   1.98781}, {13537/20, 1.99475}, {14037/20, 2.00169}, {14537/20, 
   2.00866}}, {{-(4963/20), 1.91449}, {-(4463/20), 
   1.90928}, {-(3963/20), 1.90379}, {-(3463/20), 
   1.89814}, {-(2963/20), 1.89235}, {-(2463/20), 
   1.88646}, {-(1963/20), 1.88048}, {-(1463/20), 1.87443}, {-(963/20),
    1.86831}, {-(463/20), 1.86214}, {37/20, 1.85591}, {537/20, 
   1.84964}, {1037/20, 1.84332}, {1537/20, 1.83697}, {2037/20, 
   1.83057}, {2537/20, 1.82414}, {3037/20, 1.81768}, {3537/20, 
   1.81119}, {4037/20, 1.80466}, {4537/20, 1.79811}, {5037/20, 
   1.79153}, {5537/20, 1.78492}, {6037/20, 1.77829}, {6537/20, 
   1.77163}, {7037/20, 1.76495}, {7537/20, 1.75825}, {8037/20, 
   1.75152}, {8537/20, 1.74478}, {9037/20, 1.73801}, {9537/20, 
   1.73122}, {10037/20, 1.72441}, {10537/20, 1.71758}, {11037/20, 
   1.71074}, {11537/20, 1.70388}, {12037/20, 1.697}, {12537/20, 
   1.6901}, {13037/20, 1.68318}, {13537/20, 1.67625}, {14037/20, 
   1.6693}, {14537/20, 1.66234}}, {{-(4963/20), 1.92372}, {-(4463/20),
    1.91851}, {-(3963/20), 1.91303}, {-(3463/20), 
   1.90737}, {-(2963/20), 1.90158}, {-(2463/20), 
   1.89569}, {-(1963/20), 1.88971}, {-(1463/20), 1.88366}, {-(963/20),
    1.87755}, {-(463/20), 1.87137}, {37/20, 1.86515}, {537/20, 
   1.85887}, {1037/20, 1.85256}, {1537/20, 1.8462}, {2037/20, 
   1.83981}, {2537/20, 1.83338}, {3037/20, 1.82691}, {3537/20, 
   1.82042}, {4037/20, 1.8139}, {4537/20, 1.80734}, {5037/20, 
   1.80076}, {5537/20, 1.79416}, {6037/20, 1.78752}, {6537/20, 
   1.78087}, {7037/20, 1.77418}, {7537/20, 1.76748}, {8037/20, 
   1.76075}, {8537/20, 1.75401}, {9037/20, 1.74724}, {9537/20, 
   1.74045}, {10037/20, 1.73365}, {10537/20, 1.72682}, {11037/20, 
   1.71997}, {11537/20, 1.71311}, {12037/20, 1.70623}, {12537/20, 
   1.69933}, {13037/20, 1.69241}, {13537/20, 1.68548}, {14037/20, 
   1.67854}, {14537/20, 1.67157}}, {{-(4963/20), 
   1.78417}, {-(4463/20), 1.77895}, {-(3963/20), 
   1.77347}, {-(3463/20), 1.76781}, {-(2963/20), 
   1.76203}, {-(2463/20), 1.75614}, {-(1963/20), 
   1.75016}, {-(1463/20), 1.74411}, {-(963/20), 1.73799}, {-(463/20), 
   1.73182}, {37/20, 1.72559}, {537/20, 1.71932}, {1037/20, 
   1.713}, {1537/20, 1.70664}, {2037/20, 1.70025}, {2537/20, 
   1.69382}, {3037/20, 1.68736}, {3537/20, 1.68086}, {4037/20, 
   1.67434}, {4537/20, 1.66779}, {5037/20, 1.6612}, {5537/20, 
   1.6546}, {6037/20, 1.64796}, {6537/20, 1.64131}, {7037/20, 
   1.63463}, {7537/20, 1.62792}, {8037/20, 1.6212}, {8537/20, 
   1.61445}, {9037/20, 1.60769}, {9537/20, 1.6009}, {10037/20, 
   1.59409}, {10537/20, 1.58726}, {11037/20, 1.58042}, {11537/20, 
   1.57355}, {12037/20, 1.56667}, {12537/20, 1.55977}, {13037/20, 
   1.55286}, {13537/20, 1.54593}, {14037/20, 1.53898}, {14537/20, 
   1.53202}}}

When I try to plot that with Callout, the colors of the leaders are wrong:

labelNames = Table["abcdef", Length@data];
SeedRandom[1234];
colors = RandomSample[ColorData["Atoms", "ColorList"], 
   Length@labelNames];
ListLinePlot[
 MapThread[
  Callout[#1, #2, CalloutStyle -> #3, 
    LabelStyle -> Directive[Bold, Medium, #3]] &, {data, labelNames, 
   colors}], PlotStyle -> colors, ImageSize -> Large]

enter image description here

But, when I use another similarly constructed data, the results are satisfying:

anotherData = Table[{x, a*x}, {a, -7, 6, 1}, {x, -5, 5}];
ListLinePlot[
 MapThread[
  Callout[#1, #2, CalloutStyle -> #3, 
    LabelStyle -> Directive[Bold, Medium, #3]] &, {anotherData, 
   labelNames, colors}], PlotStyle -> colors, ImageSize -> Large]

enter image description here What's wrong?

$\endgroup$
2
  • 3
    $\begingroup$ Try adding PlotRange->All - Looks like ListPlot is getting confused if some of the curves are not displayed at all, leading to the callouts being assigned to the wrong curves. $\endgroup$
    – Lukas Lang
    Apr 27, 2023 at 17:36
  • $\begingroup$ Unfortunately I don't want these 2 remaining plots to be visible by default $\endgroup$
    – Lechuu
    Apr 28, 2023 at 12:35

1 Answer 1

7
$\begingroup$

A work-around: Rotate the data two steps to the left (using RotateLeft[data,2]) so that the two datasets excluded from plot under the default setting for PlotRange are the last two datasets. (Alternatively, you can sort the input datasets by the vertical value of the last points to move the first two data sets to the end of the list.)

labelNames = Table["abc" <> ToString[i], {i, Length@data}];

SeedRandom[1234];
colors = RandomSample[ColorData["Atoms", "ColorList"], Length @ labelNames];


dataWcallouts = MapThread[
  Callout[#, #2, CalloutStyle -> #3, 
    LabelStyle -> Directive[Bold, Medium, #3]] &, 
  {RotateLeft[data, 2], RotateLeft[labelNames,2], RotateLeft[colors,2]}];


ListLinePlot[dataWcallouts, PlotStyle ->  RotateLeft[colors,2], 
 ImageSize -> Large]

enter image description here

ListLinePlot[dataWcallouts, PlotStyle ->  RotateLeft[colors,2], 
 ImageSize -> Large, PlotRange -> {1.5,.2.2}]

enter image description here

With PlotRange -> All we get

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Thank You for Your answer! Rotating is not really useful since I'm not sure which of the plots will have the highest value, so I would prefer sorting. In order to do that I have to join in list the name of the labels with data (so the labels will be sorted with data as well) and then sort by last y element in all sublists: SortBy[ Thread@{labelNames, data}, #[[-1, -1, -1]] &] $\endgroup$
    – Lechuu
    Apr 28, 2023 at 10:15

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.