Message Boards Message Boards

Create a ListLogLogPlot with countries data and use Tooltip?

Posted 7 years ago

I have found an example in the documentation of Mathematica. I tried to modify the code as a way of learning. Fortunately, I've done what I expected only if a little problem is solved, I need help :

Here is the original code :

In[1]:= datta = EntityValue[
   EntityClass["Country", "Countries"], {"Name", "Area","Population"}];

In[2]:=annotated = data /. {{n : "Macau" | "Monaco" | "India", a_, b_} :> Callout[{a, b}, n, Above], 
       {n : "Pitcairn Islands" | "Svalbard" | "Greenland", a_,b_} :> Callout[{a, b}, n, Below], 
       {r : "Russia" | "China", a_, b_} :> Callout[{a, b}, r, After], 
       {"Vatican City", a_, b_} :> Callout[{a, b}, "Vatican City", Before],
       {n_, a_, b_} :> Tooltip[{a, b}, n]}

In[3]:=ListLogLogPlot[annotated, PlotTheme -> "Detailed", FrameLabel -> Automatic]

enter image description here

I wanted to modify In[2] , here is my code:

annotated1 = 
  data /. MapThread[{#1, a_, b_} :> #2[{a, b}, n, #3] &, 
     {
     {n : "Macau" | "Monaco" | "India", 
      n : "Pitcairn Islands" | "Svalbard" | "Greenland", 
      n : "Russia" | "China", n : "Vatican City", n_}, 
     {Callout,Callout, Callout, Callout, Tooltip}, 
     {Above, Below, After,Before, **Blank**}
    }];

the problem is that Tooltip function cannot accept a third argument :

Tooltip[expr,label]

,though MapThread cannot accept a list with inferior dimension:

**Lists must be of the same dimension.**
POSTED BY: Megri Youcef
2 Replies

Then create a function, that gives you a tooltip and ignores the 3rd argument:

Tooltip[#1, #2] &

That being said, the following works

data = EntityValue[EntityClass["Country", "Countries"], {"Name", "Area", "Population"}];
annot = data /. 
   MapThread[{#1, a_, b_} :> #2[{a, b}, n, #3] &, {
    { n : "Macau" | "Monaco" | "India",
      n : "Pitcairn Islands" | "Svalbard" | "Greenland", 
      n : "Russia" | "China", n : "Vatican City", n_},
    {Callout, Callout, Callout, Callout, Tooltip[#1, #2] &}, 
    {Above, Below, After, Before, ItDoesntMatterWhatIsHere}}];

ListLogLogPlot[annot, PlotTheme -> "Detailed",  FrameLabel -> Automatic]
POSTED BY: Patrick Scheibe
Posted 7 years ago

Thank you Patrick, a good trick to bypass this problem.

POSTED BY: Megri Youcef
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract