6
$\begingroup$

A rather simple example

Clear["Global`*"];

data = TimeSeries[{1, 2, 1, 3, 0, 0, 0, 2, 21, 15, 21, 7, 11, 5, 10, 
       18, 73, 38, 103, 21, 35, 31, 46, 31, 35, 94, 71, 48, 78, 71, 74, 
       95, 95, 56, 102, 81, 119, 99, 60, 62, 20, 77, 52, 71, 56, 72, 33, 
       31, 25, 22, 15, 17, 11, 0, 10, 6, 7}, {"Feb 26, 2020"}];

plot = DateListPlot[Accumulate[data], Mesh -> All, ImageSize -> 500]

enter image description here

As you can see, the horizontal axis contains only two ticks showing only the month but not the dates. Is there a way to control the number of ticks on the horizontal axis and also print the correct values of the dates?

$\endgroup$
1
$\begingroup$

You can specify the ticks for the date axis using System`DateListPlotDump`DateTicks. This function takes two arguments: the first argument is a list of dates ({mindate, maxdate}) and the second is the number of divisions. Optional third argument can be used to specify formatting of date labels.

System`DateListPlotDump`DateTicks[arg1: {mindate, maxdate}, ndivisons, labelformat]

Using OP's input data:

DateListPlot[Accumulate[data], Mesh -> All, ImageSize -> 500, 
 FrameTicks -> {{Automatic, Automatic}, 
  {System`DateListPlotDump`DateTicks[{##}, 9, {"Year", "/", "Month", "/", "Day"}] &,
   Automatic}}]

enter image description here

Use System`DateListPlotDump`DateTicks[{##}, 5, "DateShort"] & to get

enter image description here

$\endgroup$
3
  • $\begingroup$ In version 12, I cannot reproduce your outputs. In both caes I get the following error message: "A ticks specification in the value of FrameTicks should be None, Automatic, a function, or a list of ticks." $\endgroup$ – Vaggelis_Z Apr 22 '20 at 21:14
  • $\begingroup$ try if using System`DateListPlotDump`DateTicks[data/@{"FirstDate", "LastDate"}, 9, {"Year", "/", "Month", "/", "Day"}] works. $\endgroup$ – kglr Apr 22 '20 at 22:04
  • $\begingroup$ Once more it is not working. See exactly the error messages: mediafire.com/file/mt21pbjz78z02kn/test.pdf/file $\endgroup$ – Vaggelis_Z Apr 23 '20 at 7:12

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.