2
$\begingroup$

I can get ListPlot to work with Callout. Here is toy code:

data = {0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 7, 7, 7};
val1L = ReplacePart[data, 9 -> Callout[0, "First Period End", {10, 1}]]
ListPlot[val1L, Joined -> True]

Producing:

enter image description here

If I create an EventSeries, and then rescale this to have a range of dates, like so:

es = EventSeries[val1L, Automatic]
rescaleTS = 
  Table[
    {DatePlus[
       DateObject["January 1, 2020"], {i - 1, "Month"}], 
       Normal[es][[i]][[2]]}, 
    {i, 1, es["PathLength"]}]

The first part of the output looks like this:

enter image description here

When I plot this with DateListPlot it seems to ignore the Callout wrapper, producing:

enter image description here

For completeness the DateListPlot command is just:

DateListPlot[rescaleES]
$\endgroup$
1
  • 1
    $\begingroup$ You can use Epilog, e.g., DateListPlot[rescaleTS, Epilog -> {Text["First Period End", {{2020, 9, 1}, 0}, {-1.25, -1.25}]}] $\endgroup$
    – Bob Hanlon
    Nov 18, 2020 at 17:09

1 Answer 1

4
$\begingroup$

You did not form the callout properly. Here is a way that works.

data = {0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 7, 7, 7};
es = EventSeries[data, Automatic];
rescaleTS = 
  Table[
    {DatePlus[
       DateObject["January 1, 2020"], {i - 1, "Month"}], 
       Normal[es][[i]][[2]]}, 
    {i, 1, es["PathLength"]}];
vals = ReplacePart[rescaleTS, 9 -> Callout[rescaleTS[[9]], "First Period End"]];
DateListPlot[vals]

plot

Update

However, if you were intended to label both period endings, I would recommend:

data = {0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 7, 7, 7};
es = EventSeries[data, Automatic];
rescaleTS = 
  Table[
    {DatePlus[
       DateObject["January 1, 2020"], {i - 1, "Month"}], 
       Normal[es][[i]][[2]]}, 
    {i, 1, es["PathLength"]}];
rescaleTS[[9]] = Callout[rescaleTS[[9]], "1st Period End", After];
rescaleTS[[15]] = Callout[rescaleTS[[15]], "2nd Period End", After];
DateListPlot[rescaleTS]

plot

And, actually, this approach might be better even if you only wanted one callout.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.