3
$\begingroup$

I would like to plot some data in time and am trying to format it so that tooltips on mouse over gives the date and a value.

Something of the form

    DateListPlot[Tooltip[data,
    StringForm["Time: ``, ``= ``", DateString[data[[x, 1]],{"Month","/", "Day", " ", "Hour", ":", "Minute"}],Title, data[[x, 2]]]]]

Is similar to what I want except I need data[[x,1]] or data[[x,2]] to have x as a reference to the current position DateListPlot is in the list so that mouse overs give correct time/value.

This example works when I just make x some number 1 <= x <= length(data).

$\endgroup$
1
  • $\begingroup$ Look up MapIndexed, and pure functions using (# &). $\endgroup$ Sep 8, 2014 at 5:40

1 Answer 1

12
$\begingroup$

For illustrative purposes:

dt = DateRange[{2014, 1, 1}, {2014, 1, 31}];
v = RandomInteger[{5, 10}, 31];
dat = Transpose[{dt, v}];
tt = Tooltip[#, 
     Row[{DateString[
        First@#, {"DayNameShort", ", ", "Day", " ", "MonthNameShort", 
         " ", "Year"}], ": ", Style[Last@#, Red, Bold]}], 
     TooltipStyle -> {Background -> White, CellFrameColor -> Blue, 
       CellFrame -> 2}] & /@ dat;
DateListPlot[tt, PlotMarkers -> {Style[©, Red], 20}]

enter image description here

$\endgroup$
6
  • $\begingroup$ i like the © Sign, it says see, see, see ... $\endgroup$
    – user9660
    Sep 8, 2014 at 18:46
  • $\begingroup$ Can you apply this to multiple date lists of the form {dat1,dat2} $\endgroup$
    – Boris
    May 9, 2019 at 16:21
  • $\begingroup$ @Boris if the 2 or more dat are prepared as tooltips it should work. You could write a generic function to prepare time series. Good luck :) $\endgroup$
    – ubpdqn
    May 9, 2019 at 22:56
  • $\begingroup$ Yes, I tried 2 tt functions, but this is part of a larger project and I do need a generic as you suggest. Sadly this is beyond me - I tried, believe me. Can you suggest something? $\endgroup$
    – Boris
    May 11, 2019 at 14:31
  • 1
    $\begingroup$ @Boris I would make the tooltip assignment a function then map it to your timeseries the DateListPlot. I $\endgroup$
    – ubpdqn
    May 13, 2019 at 9:18

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.