3
$\begingroup$

I would like to add notes to specific days on a DateListPlot of a stock price, and have them always be visible (not just on mouseover). So far I've got how to add a tooltip to a specific day, but not sure how to get it to remain always visible, or how to get it rotated 90 degrees, or how to make days with no tooltip appear without the red dot, or how to add a tooltip using the date instead of the index (instead of stock[[3]]=ToolTip... Id like to do stock[ where date = {2003,12,29} ] if that is possible ). Thank you for any suggestions.

stock = {{{2003, 12, 24}, 1094.04}, {{2003, 12, 26}, 1095.89}, {{2003, 12, 29}, 1109.47}, {{2003, 12, 30}, 1109.64}, {{2003, 12, 31}, 1111.92}, {{2004, 1, 2}, 1108.47}, {{2004, 1, 5}, 1122.21}}; 

stock[[3]] = Tooltip[stock[[3]], Rotate["Earnings were released lower than expected", 90], TooltipStyle -> {Background -> White, CellFrameColor -> Blue, CellFrame -> 0}];

stock[[5]] = Tooltip[stock[[5]], Rotate["Article appeared on new product launch", 90], TooltipStyle -> {Background -> White, CellFrameColor -> Blue, CellFrame -> 0}];

DateListPlot[stock, PlotMarkers -> {Style[\[Bullet], Red], 20}]
$\endgroup$
  • $\begingroup$ In your code use 90 Degree instead 90 to place tooltips vertically. But if you want they remain always visible use Text in Epilog to DateListPlot and do not redefine points: DateListPlot[stock, PlotMarkers -> {Style[\[Bullet], Red], 20}, Epilog -> {Text["Earnings were released\n lower than expected", stock[[3]], {-1, 0}, {0, 1}]}, PlotRangePadding -> {{Automatic, Automatic}, {Automatic, Scaled[0.3]}}]. Your labels are very long, so I added \n to break a string and set manually PlotRangePadding. $\endgroup$ – Alx Sep 6 at 14:28
  • $\begingroup$ Consider to shorten texts or use just simple labels 1, 2, ... and put description in caption or main text of your document. $\endgroup$ – Alx Sep 6 at 14:29
  • $\begingroup$ See also Callout command in Help. $\endgroup$ – Alx Sep 6 at 14:43
3
$\begingroup$

Too long for a comment... Example of using Callout:

stock = {{{2003, 12, 24}, 1094.04}, {{2003, 12, 26}, 1095.89}, 
Callout[{{2003, 12, 29}, 1109.47}, 
"Earnings were released\n lower than expected", Above, 
CalloutMarker -> "Circle", Appearance -> "Leader", 
LeaderSize -> 30], {{2003, 12, 30}, 1109.64}, 
Callout[{{2003, 12, 31}, 1111.92}, 
"Article appeared\n on new product launch", Below, 
CalloutMarker -> "Box", Appearance -> "Leader", LeaderSize -> 30, 
Background -> None], {{2004, 1, 2}, 1108.47}, {{2004, 1, 5}, 
1122.21}};
DateListPlot[stock]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you Alx, both of those perfectly fit the bill. Many thanks! $\endgroup$ – AndersV Sep 6 at 14:59
  • $\begingroup$ Thank you for accepting answer! And welcome to Mathematica SE! $\endgroup$ – Alx Sep 6 at 15:01

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.