5
$\begingroup$

I have a list of values associated with the xaxis, but I do not want to plot them as y values. Rather I want to do something like "TickLabels" in Matlab, but make them Tooltips (because they can be rather long). Conceptually, it would be something like this:

timepoint 1 -> "this is the first point"
timepoint 2 -> "but then we started to wander"
timepoint 3 -> "we found our way back again"
timepoint 4 -> "on track!"

For anyone who stumbles on this request: I did find this helpful guide, but it appears to expect a list of actual values (associated with location along the axis).

$\endgroup$

2 Answers 2

5
$\begingroup$
pts = {π/4, π/2, (2 π)/3, π};

msgs = {"this is the first point", "but then we started to wander", 
   "we found our way back again", "on track!"};

Show[Plot[Sin[x], {x, 0, 2 Pi}, GridLines -> {pts, None}], 
 NumberLinePlot[MapThread[Tooltip]@{pts, msgs}, 
  PlotStyle -> Directive[Red, 
    Opacity -> Dynamic[If[CurrentValue["MouseOver"], 1., .2]], 
    AbsolutePointSize[Dynamic[If[CurrentValue["MouseOver"], 15, 5]]]],
   Spacings -> 0]]

enter image description here

$\endgroup$
5
$\begingroup$
Clear["Global`*"];
pts = {π/4, π/2, 2 π/3, π};
msgs = {"this is the first point", "but then we started to wander", 
   "we found our way back again", "on track!"};
tips = Transpose[{{#, 0} & /@ pts, msgs}];

p1 = Plot[Sin[x], {x, 0, 2 Pi}
   , GridLines -> {pts, None}
   ];

p2 = Show[
   Region[
      Tooltip[Style[Point[First@#]
        , Directive[Red, AbsolutePointSize[6], Opacity[1]]]
       , Rotate[Last@#, π/2]]] & /@ tips
   ];

Show[p1, p2]

enter image description here

You can set Opacity[0] to make the Red point disappear, remove or keep the GridLines and Rotate the label (or not).

$\endgroup$
2
  • $\begingroup$ Thank you! Only one more question. Is there a way to make the gridlines invisible? The points are very close together and the gridlines will appear to occupy the entire space. $\endgroup$
    – Indiana
    Commented May 19, 2023 at 13:29
  • $\begingroup$ You could say , GridLinesStyle -> {Opacity[0], Opacity[0]} but then you could also not include those in p1. Thanks for the accept, but I would suggest that you wait 24 hours and let other answers flow in. $\endgroup$
    – Syed
    Commented May 19, 2023 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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