2
$\begingroup$

I have an x/y data set casualties with Union and Confederate Civil War casualties. I have a third variable, battles, listing the names of all of the battles. Currently Tooltip will show the x/y pairs, but I want the name of the battle when I hover over a point.

casualtiesPlot = ListPlot[
  Tooltip[
   casualties], PlotRange -> All, GridLines -> Automatic, 
  PlotLabel -> "Union vs. Confederate Casualties", 
  AxesLabel -> {"Union \n Deaths", "Confederate \n Deaths"}]
$\endgroup$
0

1 Answer 1

1
$\begingroup$
casualties = {{100, 120}, {80, 70}, {150, 190}};

battles = {"Battle-1", "Battle-2", "Battle-3"};

tips = 
 MapThread[Tooltip, {casualties, Transpose[{battles, casualties}]}];

ListPlot[
 tips,
 PlotRange -> All,
 GridLines -> Automatic,
 PlotLabel -> "Union vs. Confederate Casualties",
 AxesLabel -> {"Union \n Deaths", "Confederate \n Deaths"}]

enter image description here

To show only the name of the battle:

tips = MapThread[Tooltip, {casualties, battles}];

If you want to use options, f.e.:

tips =
 MapThread[
  Tooltip[##,
    TooltipStyle -> {Background -> GrayLevel@0.9}] &,
  {casualties, battles}];
$\endgroup$
0

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.