2
$\begingroup$

I am trying to make a set of scatterplots where the 'u' value is a year. I am using the following dataset:

DataPoints = {{{39, 34}, {58, 72}, {55, 71}, {61, 42}, {56, 60}, {23, 
    83}, {57, 70}, {54, 72}, {23, 80}, {20, 36}, {28, 64}, {25, 
    21}, {24, 90}, {57, 79}, {22, 65}, {53, 52}, {19, 74}, {63, 
    48}}, {{66, 59}, {62, 63}, {66, 37}, {65, 25}, {87, 78}, {61, 
    34}, {17, 27}, {55, 46}, {61, 38}, {70, 70}}, {{59, 43}, {55, 
    45}, {18, 16}, {29, 37}, {43, 30}, {62, 58}}, {{48, 59}, {14, 
    42}, {61, 39}, {55, 38}, {13, 38}, {17, 42}, {15, 27}, {58, 
    62}, {30, 46}, {54, 41}, {44, 23}, {53, 55}}}
Countries = {{"ARG", "CAN", "CZE", "FRA", "GER", "GHA", "ITA", "JPN", 
   "KEN", "LBN", "MEX", "PAK", "PHL", "POL", "ZAF", "KOR", "UGA", 
   "GBR"}, {"AUS", "CAN", "FRA", "GER", "ISR", "ITA", "LBN", "KOR", 
   "ESP", "GBR"}, {"FRA", "GER", "PAK", "RUS", "TUR", "GBR"}, {"CAN", 
   "CHN", "FRA", "GER", "IDN", "LBN", "PAK", "POL", "RUS", "ESP", 
   "TUR", "GBR"}}

I am using the following to do this:

Manipulate[
 Show[ListPlot[DataPoints[[year]]], 
  PlotRange -> {{0, 100}, {0, 100}}, AxesOrigin -> {0, 0}, 
  AxesLabel -> {"X", "Y"}], {{year,1}, {1 ->  "2002", 2 -> "2003", 3 -> "2004", 
   4 -> "2005"}}]

Is there a way to label each datapoint on the scatterplot with a Manipulate function? I can get it to work for one year only...

Thanks, Arebearit

Note: Edited because first problem was solved.

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Dec 28 '14 at 17:40
  • $\begingroup$ You mention an error message. I see none when running your code on V 10. $\endgroup$ – bbgodfrey Dec 28 '14 at 17:42
  • $\begingroup$ Sorry about that, I just found the error and edited it out but forgot to remove my mention of it. $\endgroup$ – arebearit Dec 28 '14 at 17:44
  • $\begingroup$ What sort of a label (content, etc.) do you wish for each point? ToolTip accommodates labels when the mouse hovers over a point. Is that useful? $\endgroup$ – bbgodfrey Dec 28 '14 at 17:51
  • $\begingroup$ Hello arebearit, what do you mean with "label each datapoint on a scatterplot..?" $\endgroup$ – mgamer Dec 28 '14 at 17:54
4
$\begingroup$

ListPlot accepts data sets with wrappers such as Tooltip, Labeled, ... , Button etc. (See this answer on various wrappers you can use with ListPlot.)

Assuming that the label you want to attach to a point in dataPoints is the country label in the same position in countries, you can pre-process dataPoints and countries using Labeled to produce a labeled data set.

labeleddata=Thread[Labeled[First@# ,Last@#]]&/@Transpose[{dataPoints,countries}];

Manipulate[Show[ListPlot[labeleddata[[year]]], 
  PlotRange -> {{0, 100}, {0, 100}}, AxesOrigin -> {0, 0}, AxesLabel -> {"X", "Y"}], 
  {{year,1}, {1 ->  "2002", 2 -> "2003", 3 -> "2004",  4 -> "2005"}}]

enter image description here

$\endgroup$
  • $\begingroup$ very nice. Could you add a brief explanation of why it works? Thanks. $\endgroup$ – bbgodfrey Dec 28 '14 at 18:16
  • $\begingroup$ Thank you @bbgodfrey. I will add some notes in a few minutes. $\endgroup$ – kglr Dec 28 '14 at 19:04
  • $\begingroup$ Thank you. I could not find this capability in the ListPlot documentation. Is it undocumented, or located somewhere else in the copious Mathematica documentation? If undocumented, how did you discover it in the first place? $\endgroup$ – bbgodfrey Dec 28 '14 at 20:17
  • 1
    $\begingroup$ @bbgodfrey, as of v9, these features were undocumented; v10 ListPlot documentation does not mention them either. How I discovered was by trial/luck based on the hunch: if Tooltip works, maybe so would other wrappers ... $\endgroup$ – kglr Dec 28 '14 at 20:45
  • $\begingroup$ What a fantastic find @kguler! Thank you so much for this! $\endgroup$ – arebearit Dec 28 '14 at 22:23

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.