It is not very surprising that plotting a PackedArray
is faster to plot than a list of pairs (date, value), nonetheless the plotting time may be prohibitive with DateListPlot
.
The function benchmark
below takes a size as an argument, and compute a list of points to plot in three different ways:
ListLinePlot
ofList
of pairs (real, real)DateListPlot
ofList
of pairs (date, real)DateListPlot
ofTimeSeries
As you can see, ListLinePlot
is much faster.
benchmark[n_] := Block[{y, t, t2, ts},
y = RandomReal[{0, 10}, n];
t = Sort@RandomReal[{UnixTime[], UnixTime[] + 10000}, n];
t2 = FromUnixTime /@ t;
ts = TimeSeries[Transpose@{t2, y}];
{AbsoluteTiming@ListLinePlot[Transpose[{t, y}]],
AbsoluteTiming@DateListPlot[Transpose[{t2, y}]],
AbsoluteTiming@DateListPlot@ts}[[All, 1]]
]
nvals = 75*Range[60]^2;
tab = ParallelTable[benchmark[n], {n, nvals}];
ListLinePlot[Transpose[{nvals, #}] & /@ Transpose@tab,
PlotLabel -> "Timing vs Size", PlotLabels -> {"ListLinePlot", "DateListPlot",
"DateListPlot@TimeSeries"}, ImageSize -> Large]
In practice, waiting several seconds can be limiting, for example when plotting multiple curves with long time series with a dynamic range selection.
In such cases, using DateListPlot
is prohibitive, so I would like to use ListLinePlot
instead. However, the date formatting is neat.
Question Is it possible to display dates on the $x$-axis with ListLinePlot
, to mimick the rendering of DateListPlot
while preserving an efficient timing?