3
$\begingroup$

I would like to generate a ListPlot with labels that appear when the pointer goes over the individual points. Specifically, I have a table of dimensions {100,3} and I want to use the first two columns for the plot and the third for the label.

Does anyone know how to do that?

$\endgroup$
4
  • $\begingroup$ Maybe something like: ListPlot[Tooltip@Prime[Range[25]], Filling -> Axis]. Is that what you try to do? $\endgroup$ Feb 1 '13 at 14:55
  • $\begingroup$ Thanks! It is almost what I want. Say that I have a table tab of dimensions {100,3} and I want to use the first two columns for the plot and the third for the label. Do you know how to do that? $\endgroup$
    – Valerio
    Feb 1 '13 at 15:04
  • 1
    $\begingroup$ Please update your question with the additional information you supplied in your comment. It makes the question quite different than as originally posted. $\endgroup$
    – m_goldberg
    Feb 1 '13 at 15:31
  • 1
    $\begingroup$ Also have a look at BubbleChart. $\endgroup$
    – Jens
    Feb 1 '13 at 17:39
8
$\begingroup$

Based on update question: It seems that ListPlot cannot handle Tooltip "directly", so I used a Table to add a Tooltip to each point.

I use the following random data:

data = Append[#, RandomChoice[{"label1", "label2", "label3"}]] & /@ 
RandomInteger[100, {10, 2}] 

(*{{80, 14, "label1"}, {98, 70, "label1"}, {66, 86, "label3"}, {43, 90, 
"label2"}, {82, 29, "label2"}, {65, 91, "label1"}, {68, 59, 
 "label3"}, {9, 56, "label1"}, {17, 50, "label2"}, {79, 99, 
 "label3"}}*)

And then plot:

ListPlot[Table[Tooltip[data[[i, 1 ;; 2]], data[[i, 3]]], {i, Length@data}]]

pointless animation added

Is this what you wanted?

EDIT

Based on Mr.Wizard's comment (see below), we can also concisely write:

ListPlot[Tooltip[{#, #2}, #3] & @@@ data]
$\endgroup$
6
  • 1
    $\begingroup$ added pictures... ;) $\endgroup$
    – cormullion
    Feb 1 '13 at 16:35
  • $\begingroup$ @cormullion: thanks! that's something I never really understood on my mac... $\endgroup$ Feb 1 '13 at 16:38
  • $\begingroup$ You can use QuickTimePlayer to record the screen, then import the file and export it to animated GIF. Of course, embedded movies would be easier... $\endgroup$
    – cormullion
    Feb 1 '13 at 16:46
  • $\begingroup$ ah thanks, I'll try that! (for next time) $\endgroup$ Feb 1 '13 at 16:54
  • $\begingroup$ Good answer. However, you should read this, and then understand: ListPlot[Tooltip[{#, #2}, #3] & @@@ data] $\endgroup$
    – Mr.Wizard
    Mar 13 '13 at 16:07

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.