4
$\begingroup$

I'm trying generate a simlilar graph to the one shown at https://ourworldindata.org/co2/country/greece?country=~GRC

enter image description here

On this graph, when you hover over a data point, the information is displayed and a vertical line is generated.

Here is some data.

data = Table[{i, Prime[i]}, {i, 25}];
ListPlot[Tooltip[data, DateString[]]]

This generates a graph that when you hover over a data point, the date is displayed.

enter image description here

How can I generate a plot, that when i hover over the point, a vertical line is generated like in the example?

$\endgroup$

2 Answers 2

4
$\begingroup$

In this approach, with Epilog or Prolog, the line generation is independent of the Tooltip:

ListPlot[Tooltip[data, DateString[]],
 Epilog -> Dynamic@{Thin,
    Replace[
     MousePosition[
      "Graphics"], {p_?VectorQ :> InfiniteLine[Round@p, {0, 1}],
      None :> Nothing}
     ]}]
$\endgroup$
5
$\begingroup$

Here's a start:

data = Table[{x, N@Exp[x]}, {x, 0, 3, 0.2}];

ClearAll[annotate]
annotate[set_] := Map[
   Mouseover[Tooltip[Point[#], #], {Point[#], Line[{{#[[1]], 0}, #}]}] &,
   set
 ]

Graphics[
  annotate[data],
  AspectRatio -> 1/GoldenRatio,
  Axes -> True, PlotRangePadding -> Scaled[.05]
]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.