8
$\begingroup$

I have a ListPlot where I plot multiple lists. I would like to highlight specific points on the x axis. I know I can use GridLines to render vertical lines at given x values.

Thus the question is how can I do this?

  • Should I label a GridLine?
  • Should I use a Callout? If that is the case, can I have one Callout for multiple groups? (e.g. highlight the same point on multiple lines with a single blurb?).
  • Should I plot a vertical line within ListPlot and give that a Callout?
  • Should I use a Graphics primitive, e.g. Graphics[Line[{{3, -5}, {3, 5}}], PlotRange -> 5, Axes -> True]

How would I do any of those as they are not examples in the documentation?

Note:

  • Labeled with Graphics works, but not in conjunction with Show and Plot.
  • Appending Callout[{x,y},"Test",Above] to one of the lists to plot does not work.

  • Adding {Callout[{x,y},"Test",Above]} as another list in ListPlot produces a single point.

$\endgroup$

1 Answer 1

8
$\begingroup$

Basic Answer

This is a non-ideal solution. One can make the GridLines as shown in the documentation or on other S.E. questions. Then using Show add a ListPlot with one list containing the desired label, e.g.

Show[
  <Other Plotting Things>
  ListPlot[
    {myListOne, myListTwo, {Callout[{x, y}, "my label", Above]}}, 
    <GridLine Specifications>
  ]
]

Where x is the same as where the GridLines are specified, and y is the position at which to make the Callout.

Example

Here is a working example:

Show[
 Plot[
  {Sin[x], Cos[x]}, {x, 0, 5}, 
  GridLines ->
   {
    {
     {1, Directive[Thickness -> .001, Black]},
     {3, Directive[Thickness -> .001, Black]}
     },
    {0}
    }, 
  ImageSize -> Large ,
  PlotLabel -> "Labeling GridLines", 
  AxesLabel -> {"x", "y"}
  ],
 ListPlot[
  {
   {Callout[{1, 0.5}, "Label One", Right],
    Callout[{3, 0.5}, "Label Two", Right]
    }
   }
  ]
 ]

enter image description here

Notes

Do you think this is ugly? Me too. You can use all your favorite Directives to modify the Callout to make up for it. e.g. in ListPlot use PlotStyle->Opacity[0] to make the point it renders invisible.

enter image description here

Ask another question about making a beautiful call to suit your needs.

$\endgroup$
1
  • $\begingroup$ it is unfortunate you cannot add a Callout on Gridlines! Great answer, thanks! $\endgroup$
    – alex
    Apr 18, 2022 at 10:54

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.