3
$\begingroup$

I first need to build the following chart to explain what I'm trying to accomplish:

data = {{"29-1141", 186, 112}, {"41-2031", 123, 92},
       {"41-1011", 65, 404}, {"43-4051", 108, 646},
       {"31-1014", 643, 246}, {"49-9071", 356, 363},
       {"43-1011", 543, 381}, {"43-5081", 268, 674},
       {"53-3032", 416, 653}, {"37-3011", 514, 428},
       {"37-2012", 501, 58}, {"33-9032", 441, 598},
       {"35-2014", 633, 138}, {"29-2061", 414, 590},
       {"53-3033", 98, 155}, {"35-3031", 179, 431},
       {"49-3023", 93, 623}, {"35-3021", 37, 578},
       {"41-2011",256, 237}, {"37-2011", 302, 50},
       {"47-1011", 518, 2}, {"11-9111", 313, 294},
       {"31-9092", 698, 136}, {"43-3031", 608, 610},
       {"43-6013", 562, 515}, {"13-2011", 415, 327},
       {"21-1093", 191, 72}, {"41-4012", 212, 92},
       {"41-3031", 546, 418}, {"31-1011", 591, 49},
       {"47-2031", 405, 526}, {"41-3021", 191, 297},
       {"15-1151", 442, 445}, {"43-6011", 118, 185},
       {"49-1011", 472, 402}, {"53-7062", 348, 552},
       {"43-4171", 409, 396}, {"43-6014", 348, 247},
       {"53-1031", 629, 59}, {"47-2061", 589, 534},
       {"27-1026", 22, 377}, {"29-1069", 445, 74},
       {"49-9021", 647, 539}, {"43-9061", 25, 543},
       {"11-1021", 19, 165}, {"41-1012", 482, 199},
       {"29-1062", 1, 68}, {"43-4081", 217, 112},
       {"41-3099", 663, 66}, {"11-3031", 329, 392},
       {"53-7061", 357, 515}, {"35-2021", 488, 245},
       {"31-9091", 318, 679}, {"51-1011", 650, 349},
       {"11-9051", 38, 145}, {"53-3031", 166, 691},
       {"39-9021", 561, 127}, {"39-5012", 665, 362},
       {"47-2111", 397, 532}, {"43-3071", 326, 271},
       {"29-2034", 361, 450}, {"35-9011", 12, 366},
       {"29-1123", 16, 211}, {"15-1142", 162, 662},
       {"11-2021", 520, 164}, {"29-2031", 339, 619},
       {"25-2011", 263, 564}, {"41-4011", 551, 301},
       {"29-2055", 76, 549}, {"29-2052", 285, 640},
       {"13-2072", 370, 542}, {"35-2012", 512, 547},
       {"11-2022", 130, 154}, {"15-1132", 188, 274},
       {"13-2052", 338, 587}, {"15-1199", 455, 5},
       {"35-9031", 595, 472}, {"17-2051", 648, 481},
       {"11-9199", 430, 189}, {"39-3091", 29, 396},
       {"47-2152", 412, 342}, {"29-1122", 582, 20},
       {"11-9141", 276, 4}, {"25-2021", 666, 617},
       {"15-1134", 236, 334}, {"37-1011", 407, 664},
       {"29-1063", 260, 278}, {"49-3031", 161, 354},
       {"41-9022", 185, 144}, {"41-9041", 551, 628},
       {"25-2031", 529, 505}, {"29-2071", 548, 296},
       {"29-1127", 373, 124}, {"21-1023", 473, 71},
       {"29-1067", 489, 569}, {"29-1071", 539, 277},
       {"11-3121", 390, 348}, {"11-9021", 634, 20},
       {"53-3041", 589, 258}, {"49-3021", 47, 206}};

Next:

minx = Round[Min[data[[All, 2]]]];
maxx = Round[Max[data[[All, 2]]]];
dx = Round[Subdivide[minx, maxx, 3]];

miny = Round[Min[data[[All, 3]]]];
maxy = Round[Max[data[[All, 3]]]];
dy = Round[Subdivide[miny, maxy, 3]];

gridpts = Tuples[{dx, dy}];

 regions = {Rectangle[gridpts[[1]], gridpts[[6]]], 
  Rectangle[gridpts[[5]], gridpts[[10]]], 
  Rectangle[gridpts[[9]], gridpts[[14]]], 
  Rectangle[gridpts[[2]], gridpts[[7]]], 
  Rectangle[gridpts[[6]], gridpts[[11]]], 
  Rectangle[gridpts[[10]], gridpts[[15]]], 
  Rectangle[gridpts[[3]], gridpts[[8]]], 
  Rectangle[gridpts[[7]], gridpts[[12]]], 
  Rectangle[gridpts[[11]], gridpts[[16]]]};

colors = {Magenta, Orange, Cyan, Red, Blue, Green, LightGray, Yellow, 
   Black};

pts = Table[
    Select[data, #[[{2, 3}]] \[Element] r &], {r, 
     regions}] /. {} -> {{}};

addTooltips = 
  Table[If[# === {}, Style[{0, 0}, Opacity[0]], 
       Tooltip[#[[{2, 3}]], #[[1]]]] & /@ p, {p, #}] &;

chart = ListPlot[addTooltips@pts, Frame -> True, PlotStyle -> colors, 
  GridLines -> {dx, dy}, Axes -> False, 
  PlotRange -> {{minx, maxx}, {miny, maxy}}, AspectRatio -> 1, 
  BaseStyle -> PointSize[Large]]

If you now sweep the chart with your mouse' s cursor over the points, you will be able to see the labels associated with each point on the chart; thanks to the Tooltip used for this purpose.

My question is; WITHOUT using Adobo Photoshop or any other "gif builder" software; how can one build the following movie WITHIN MATHEMATICA; so that the movie can be exported from Mathematica; into your working directory; in gif format?

Gif Movie:

Thank you!

$\endgroup$
  • 1
    $\begingroup$ That will be very hard to do: There is no way (as far as I know) to get a "screenshot" of what the frontend displays - you can get an image of the plot itself, but any tooltips/cursor will be missing. If you really wanted to, you could draw your own mouse pointer together with the tooltip, record mouse movements (using MousePosition), and render everything into a movie. But I really don't see a good reason for this - it is way more work to set up and use, and way slower $\endgroup$ – Lukas Lang Oct 2 '19 at 20:58
0
$\begingroup$

Here is an option for cycling through the labels.

frames = Table[
   ListPlot[
    Join[pts[[All, All, {2, 3}]], {{Callout[p[[{2, 3}]], p[[1]], Below, 
        Appearance -> "Frame"]}}], Frame -> True, 
    PlotStyle -> Join[colors, {{Opacity[0]}}], GridLines -> {dx, dy}, 
    Axes -> False, PlotRange -> {{minx, maxx}, {miny, maxy}}, 
    AspectRatio -> 1, BaseStyle -> PointSize[Large]], {p, data}];

Export["regionsplot2.gif", frames, "AnimationRepetitions" -> Infinity, "DisplayDurations" -> 3]

enter image description here

Or for just pointing to a subset of the data, for example 20 random points:

randompts = RandomSample[data, 20];

And replace the Table iterator with {p, randompts}.

$\endgroup$
  • $\begingroup$ Thank you @MelaGo for your amazing answer! I wanted to "film" some points of interest; i.e.; the gray points (Low Ads -High Openings); the black points (High Ads - High Openings) and the Cyan points (High Ads - Low Openings) using the mouse cursor. But, I have opted instead to generate the list of industries corresponding to those three scenarios and export them as Excel workbooks. I accept your answer; and thank you for solving a "real life problem" for us (plural because I hope this example will help many others with similar tasks). $\endgroup$ – Gilmar Rodriguez Pierluissi Oct 3 '19 at 13:44
  • $\begingroup$ @GilmarRodriguezPierluissi You're welcome. Btw if you wanted to point out one region, for example just the grey points, you could do so by replacing the Table iterator with {p, pts[[7]]}. $\endgroup$ – MelaGo Oct 3 '19 at 17:21
  • $\begingroup$ Thank you @MelaGo for showing us how to isolate one region by replacing the Table iterator with {p, pts[[k]]} where k is element of {1,...,9}. $\endgroup$ – Gilmar Rodriguez Pierluissi Oct 8 '19 at 19:57

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.