6
$\begingroup$

I am trying to use Mathematica to do some data analysis. I am trying to label points in a plot of a dataset. I know that Callout should work, but can't for the life of me figure out how to make it when I'm plotting b against a and then labeling the points with c.

Here is a subset of the dataset:

dataset = 
  Dataset[{
   <|"a" -> 0.0, "b" -> -1.26, "c" -> 1|>,
   <|"a" -> 0.3, "b" -> -1.25, "c" -> 2|>,
   <|"a" -> 0.6, "b" -> -1.26, "c" -> 3|>,
   <|"a" -> 0.9, "b" -> -1.19, "c" -> 4|>,
   <|"a" -> 1.2, "b" -> -0.8, "c" -> 5|>,
   <|"a" -> 1.5, "b" -> -0.98, "c" -> 6|>}]

ListLinePlot[Callout[dataset[All, {1, 2}], dataset[All, 3]]]

enter image description here

This doesn't give me what I want as I want to label each point.

I realize I'm missing something fundamental in terms of associating each point. Any assistance is appreciated.

Thanks for the two solutions. I want to modify the plot by assigning the plot to "g" and then using Show:

Show[g, ScalingFunctions -> "Reverse", PlotTheme -> "Detailed"]

but do not see how to do it. I tried using Show without success.

$\endgroup$
6
  • 2
    $\begingroup$ Does dataset[Map[Callout[{#a, #b}, #c] &] /* ListLinePlot] do what you want? $\endgroup$ Feb 12 '21 at 14:43
  • $\begingroup$ Yes. Thanks. Hard to get my head around some of Mathematica's cryptic code. $\endgroup$
    – reo
    Feb 12 '21 at 14:58
  • 1
    $\begingroup$ Alright, I'll post an answer later... $\endgroup$ Feb 12 '21 at 15:10
  • 6
    $\begingroup$ @J.M.'sennui That could also be written as dataset[ListLinePlot, Callout[{#a, #b}, #c] &]. $\endgroup$
    – WReach
    Feb 12 '21 at 15:39
  • $\begingroup$ @WReach, that's way less awkward; please write an answer so I can upvote it. :) $\endgroup$ Feb 12 '21 at 15:42
6
$\begingroup$

As suggested by @J.M.~~___, here is one way to do it:

dataset[ListLinePlot, Callout[{#a, #b}, #c] &]

Additional options can be added to ListLinePlot like this:

dataset[
  ListLinePlot[#, ScalingFunctions->"Reverse", PlotTheme->"Detailed"]&
, Callout[{#a, #b}, #c] &
]

ListLinePlot image

$\endgroup$

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.