# SetOptions for CoordinatesToolOptions for DateListPlot?

Bug introduced in 10.0 and persisting through 11.0 or later

DateListPlot does not respect my Options setting for CoordinatesToolOptions:

SetOptions[
DateListPlot,
CoordinatesToolOptions -> {"DisplayFunction" -> MapAt[DateString, 1]}
];

DateListPlot[{{1, 1, 2, 3, 5, 8, 11}, {5, 8, 9, 6, 2, 4, 7}}, {2013, 1, 1},
Joined -> True]


However if this option is given explicitly it works as desired:

DateListPlot[{{1, 1, 2, 3, 5, 8, 11}, {5, 8, 9, 6, 2, 4, 7}}, {2013, 1, 1},
Joined -> True, CoordinatesToolOptions -> {"DisplayFunction" -> MapAt[DateString, 1]}]


1. Why is my global Option value ignored?

2. What is the cleanest way to make DateListPlot respect my setting?

(Observations in 10.0.2 under Windows.)

• I am too tired to work through this right now so I would like to let the community solve it for me while I sleep. :^) – Mr.Wizard Apr 16 '15 at 6:07
• MapAt[DateString, 1] throws error called with 2 arguments, 3 arguments expected. or do I miss something ? PS; I didn't know that wizards sleep ??? – penguin77 Apr 16 '15 at 7:24
• @penguin77 It is a version 10+ operator form – Mr.Wizard Apr 16 '15 at 14:01
• I observe the same behavior in V10.1 (Mac OSX). – Michael E2 Apr 16 '15 at 16:29
• I already had looked at it and tried to figure it out. I gave up before I got very far. I would agree that it is a bug. – Michael E2 Apr 21 '15 at 18:04

## 2 Answers

The option value is ignored because DateListPlot calls GraphicsDateListPlotDumpiDateListPlot which only uses Options for these items:

{PlotRange, AxesOrigin, GridLines, GridLinesStyle, Epilog, Prolog, Frame, Axes, Ticks,
FrameTicks, DateTicksFormat, DateFunction, DataRange, PlotRangePadding, PlotLegends,
PlotStyle, PlotMarkers, Joined, BaseStyle, LabelStyle, TargetUnits, Method}


The values of these options are modified as needed, then combined with explicit options after the latter are filtered with:

opts = FilterRules[opts, Options[If[caller === DateListLogPlot, ListLogPlot, ListPlot]]];


Therefore we can patch the broken definition with this replacement:

DateListPlot; (* preload; do not remove! *)

With[
{dv := DownValues[GraphicsDateListPlotDumpiDateListPlot]},
dv = dv /.
(fr : FilterRules)[a : GraphicsDateListPlotDumpopts, b_Options] :>
fr[Join[a, Options @ GraphicsDateListPlotDumpcaller], b]
];


Now:

SetOptions[DateListPlot,
CoordinatesToolOptions -> {"DisplayFunction" -> MapAt[DateString, 1]}];

DateListPlot[{{1, 1, 2, 3, 5, 8, 11}, {5, 8, 9, 6, 2, 4, 7}}, {2013, 1, 1},
Joined -> True]


• +1. Nice spelunking. Note that the DateListPlot stuff has to be loaded before you fix the options. (I did it on a new kernel and it had no effect the first time.) Simply prepending DateListPlot; before With is sufficient, as you would probably know. – Michael E2 Apr 21 '15 at 18:06
• @Michael Thanks. For some reason it seemed like preloading was not needed here but now that I try it again it seems it is; I don't know what mistake I made, but this is a good lesson to use preloading as a matter of practice. Correction imminent. – Mr.Wizard Apr 21 '15 at 18:59
• @Michael I'll bet I used SetOptions[DateListPlot, . . .] before the replacement patch in my testing; I cannot think of another explanation for the behavior I observed earlier. – Mr.Wizard Apr 21 '15 at 19:04
• SetOptions[DateListPlot, ... ] still does not work properly in 10.2 -- I tried PlotLegends -> Automatic and it is not working. – gwr Jul 23 '15 at 16:26
• @Mr.Wizard Use SetOptions[ DateListPlot, PlotLegends -> Automatic] then simply plot two TimeSeries by DateListPlot[TimeSeries @@@ {{{1, 2, 3}, {1}}, {{3, 4, 5}, {1}}}]. Result: No legends, but if you add the options directly they will be plotted. – gwr Jul 24 '15 at 8:51

You may consider this:

DateListPlot[{{1, 1, 2, 3, 5, 8, 11}, {5, 8, 9, 6, 2, 4, 7}}, {2013,1,1}, Joined -> True,
CoordinatesToolOptions -> {"DisplayFunction" -> (DateString@First@# &)}]


Then let's try this:

SetOptions[DateListPlot,
CoordinatesToolOptions -> {"DisplayFunction" -> (DateString@First@# &)}];
DateListPlot[{{1, 1, 2, 3, 5, 8, 11}, {5, 8, 9, 6, 2, 4, 7}}, {2013,
1, 1}, Joined -> True]


Works perfectly well using M9. Sorry cannot test under M10.0.2.

Not sure what went wrong in your example. May be the expression following "DisplayFunction"-> was not enclosed in parenthesis (), or there might be an incompatible issue with M10?

Coordinates showing date string and value:

SetOptions[DateListPlot,
CoordinatesToolOptions -> {"DisplayFunction" ->
(Row[{DateString@First@#, " -> ", Last@#}] &)}];

DateListPlot[{{1, 1, 2, 3, 5, 8, 11}, {5, 8, 9, 6, 2, 4, 7}}, {2013,1, 1}, Joined -> True]


• Can anybody please try the code above to see if it works under M10.0.2 ? Before Mr Wizard wakes up, please, psssst :) – penguin77 Apr 16 '15 at 11:58
• Oops, too late! ;-) – Mr.Wizard Apr 16 '15 at 14:02
• This does not work in 10.0.2 so I must assume it is a bug. I'll wait for confirmation from other before tagging it as such. Hopefully it is fixed in 10.1.0. – Mr.Wizard Apr 16 '15 at 14:03
• – Dr. belisarius Apr 16 '15 at 14:04
• @Mr.Wizard, if not fixed in 10.1.0 we can swap our Mma licenses.........it's called the penguin's trick,.....undocumented.... :) – penguin77 Apr 16 '15 at 19:15