2
$\begingroup$

This code produces a DateListPlot such that when I select Get Coordinates, hovering over a point with the mouse will generate a tooltip displaying the timestamp for that point as well as the associated value.

DateListPlot[pointsETHtehran[[;; 400]], 
 PlotRange -> {{{2020, 1, 2, 4, 0, 0.}, {2020, 1, 3, 8, 0, 0.}}, 
   Automatic}, 
 CoordinatesToolOptions -> {"DisplayFunction" -> 
    MapAt[DateString, 1]}]

This produces an example tooltip of the format

{Thu 2 Jan 2020 07:31:49 100.166}

The problem arises when I embed 2 such plots in a GraphicsColumn command in order to be able to compare the aligned graphs.

GraphicsColumn[{DateListPlot[pointsETHtehran[[;; 400]], 
   PlotRange -> {{{2020, 1, 2, 4, 0, 0.}, {2020, 1, 3, 8, 0, 0.}}, 
     Automatic}], 
  DateListPlot[pointsRTHtehran[[;; 340]], 
   PlotRange -> {{{2020, 1, 2, 4, 0, 0.}, {2020, 1, 3, 8, 0, 0.}}, 
     Automatic}]}, 
 CoordinatesToolOptions -> {"DisplayFunction" -> 
    MapAt[DateString, 1]}]

This produces an example tooltip like

{Mon 1 Jan 1900 00:01:26, -97.9167}

These points lie outside of the domain of the data. What appears to be happening is that the coordinates are being returned as pixel positions rather than in terms of the data domain. (This can be confirmed by removing the specification for the DisplayFunction above.)

I tried moving the CoordinatesToolOptions specification to within the DateListPlot function itself but this makes things worse in that the DisplayFunction is no longer recognized and only raw pixel coordinates are returned.

Is there any way of forcing GraphicsColumn to return the coordinates expressed in the appropriate space?

thanks

$\endgroup$
1
  • $\begingroup$ Not really a solution but a quick workaround is to specify CoordinatesToolOptions within DateListPlot and then use Column instead of GraphicsColumn. $\endgroup$ Feb 1 at 19:50
2
$\begingroup$

You might be able to use ResourceFunction["PlotGrid"], which will preserve any settings for CoordinatesToolOptions:

data = {{DateObject[{2016, 10, 1}, "Day", "Gregorian", -5.`], 10}, {DateObject[{2016, 10, 15}, "Day", "Gregorian", -5.`], 17}, {DateObject[{2016, 10, 30}, "Day", "Gregorian", -5.`], 15}, {DateObject[{2016, 11, 20}, "Day", "Gregorian", -5.`], 20}};
ResourceFunction["PlotGrid"][
 {
  {DateListPlot[data, CoordinatesToolOptions -> {"DisplayFunction" -> MapAt[DateString, 1]}]},
  {DateListPlot[data]}
  },
 Spacings -> 30
 ]

enter image description here

Please note that the current version of PlotGrid has a small bug that causes the text "False" to appear above DateListPlot objects. To work around this until the fixed version is available, the easiest solution is to add the setting "ShowFrameLabels" -> Directive[Top -> None] to forcefully hide the top frame ticks of all plots (hence removing the spurious False)

$\endgroup$
1
  • $\begingroup$ Works beautifully. Thanks for putting in the effort to create this. $\endgroup$ Feb 2 at 19:27

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.