9
$\begingroup$

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]

enter image description here

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]}]

enter image description here

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.)

$\endgroup$
  • $\begingroup$ 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. :^) $\endgroup$ – Mr.Wizard Apr 16 '15 at 6:07
  • $\begingroup$ 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 ??? $\endgroup$ – penguin77 Apr 16 '15 at 7:24
  • $\begingroup$ @penguin77 It is a version 10+ operator form $\endgroup$ – Mr.Wizard Apr 16 '15 at 14:01
  • 1
    $\begingroup$ I observe the same behavior in V10.1 (Mac OSX). $\endgroup$ – Michael E2 Apr 16 '15 at 16:29
  • 1
    $\begingroup$ 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. $\endgroup$ – Michael E2 Apr 21 '15 at 18:04
4
$\begingroup$

The option value is ignored because DateListPlot calls Graphics`DateListPlotDump`iDateListPlot 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[Graphics`DateListPlotDump`iDateListPlot]},
  dv = dv /.
    (fr : FilterRules)[a : Graphics`DateListPlotDump`opts, b_Options] :> 
      fr[Join[a, Options @ Graphics`DateListPlotDump`caller], 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]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ +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. $\endgroup$ – Michael E2 Apr 21 '15 at 18:06
  • $\begingroup$ @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. $\endgroup$ – Mr.Wizard Apr 21 '15 at 18:59
  • $\begingroup$ @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. $\endgroup$ – Mr.Wizard Apr 21 '15 at 19:04
  • 1
    $\begingroup$ SetOptions[DateListPlot, ... ] still does not work properly in 10.2 -- I tried PlotLegends -> Automatic and it is not working. $\endgroup$ – gwr Jul 23 '15 at 16:26
  • 1
    $\begingroup$ @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. $\endgroup$ – gwr Jul 24 '15 at 8:51
0
$\begingroup$

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]

enter image description here

$\endgroup$
  • $\begingroup$ Can anybody please try the code above to see if it works under M10.0.2 ? Before Mr Wizard wakes up, please, psssst :) $\endgroup$ – penguin77 Apr 16 '15 at 11:58
  • $\begingroup$ Oops, too late! ;-) $\endgroup$ – Mr.Wizard Apr 16 '15 at 14:02
  • $\begingroup$ 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. $\endgroup$ – Mr.Wizard Apr 16 '15 at 14:03
  • $\begingroup$ Anyway, His uniqueness isn't a proven fact $\endgroup$ – Dr. belisarius Apr 16 '15 at 14:04
  • 1
    $\begingroup$ @Mr.Wizard, if not fixed in 10.1.0 we can swap our Mma licenses.........it's called the penguin's trick,.....undocumented.... :) $\endgroup$ – penguin77 Apr 16 '15 at 19:15

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.