0
$\begingroup$

I'm running an incredibly old version of Mathematica: version 9.0 (how embarassing!).

  • I have a list of (x, y) ordered pairs that I can plot using ListPlot. In the minimal working example (MWE) below, cosData is my list of ordered pairs.
  • I like to "annotate" my ListPlots with additional plot points and Graphics objects (specifically, styled Text). In the MWE below, the first Show object (with the heading (* ListPlot example *)) demonstrates this.
  • Now suppose that I need to re-plot the data with the horizontal axis having a logarithmic scale. This can be done using
    ListLogLinearPlot, as shown in the second Show object ((* ListLogLinearPlot example *)) below. However, when I attempt to annotate with ListPlot and Graphics using Show, the annotations do not appear on the plot, as demonstrated in the second Show object below.
  • I have found that the red circle annotation can be displayed by simply changing ListPlot to ListLogLinearPlot, as shown in the third Show object ((* revised ListLogLinearPlot example *)) below. But the text annotation, using Graphics with real two-dimensional coordinates, does not appear.

So, my question is: how can I add coordinate-based Graphics/Text to a ListLogLinearPlot, using the tools available in Mathematica 9.0?

cosData = Table[{N[x], N[Cos[x]]}, {x, 0, 13 Pi, Pi/20}];
pointOfInterest = {18.8496, 1.0};
plotMarkerSize = 0.1;

(* ListPlot example *)
Show[{
  ListPlot[cosData, PlotRange -> {-1.5, 1.5}, Frame -> True, 
   Joined -> True, PlotStyle -> Blue],
  ListPlot[{pointOfInterest}, PlotRange -> All, PlotStyle -> Red, 
   PlotMarkers -> {Graphics[{Red, Circle[]}], plotMarkerSize}],
  Graphics[
   Text[Style["This is an annotation.", FontFamily -> "Arial"], 
    pointOfInterest, {-1, -2.5}]
   ]
  }]

first example

cosData = Table[{N[x], N[Cos[x]]}, {x, 0, 13 Pi, Pi/20}];
pointOfInterest = {18.8496, 1.0};
plotMarkerSize = 0.1;

(* ListLogLinearPlot example *)
Show[{
  ListLogLinearPlot[cosData, PlotRange -> {-1.5, 1.5}, Frame -> True, 
   Joined -> True, PlotStyle -> Blue],
  ListPlot[{pointOfInterest}, PlotRange -> All, PlotStyle -> Red, 
   PlotMarkers -> {Graphics[{Red, Circle[]}], plotMarkerSize}],
  Graphics[
   Text[Style["This is an annotation.", 
     FontFamily -> "Arial"], {18.8496, 1.0}, {-1, -1}]
   ]
  }]

second example

cosData = Table[{N[x], N[Cos[x]]}, {x, 0, 13 Pi, Pi/20}];
pointOfInterest = {18.8496, 1.0};
plotMarkerSize = 0.1;

(* revised ListLogLinearPlot example *)
Show[{
  ListLogLinearPlot[cosData, PlotRange -> {-1.5, 1.5}, Frame -> True, 
   Joined -> True, PlotStyle -> Blue],
  ListLogLinearPlot[{pointOfInterest}, PlotRange -> All, 
   PlotStyle -> Red, 
   PlotMarkers -> {Graphics[{Red, Circle[]}], plotMarkerSize}],
  Graphics[
   Text[Style["This is an annotation.", 
     FontFamily -> "Arial"], {18.8496, 1.0}, {-1, -1}]
   ]
  }]

third example

$\endgroup$

1 Answer 1

1
$\begingroup$

I think this is probably compatible with v9

$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global`*"]

cosData = Table[{N[x], N[Cos[x]]}, {x, 0, 13  Pi, Pi/20}];

pointOfInterest = {18.8496, 1.0};
plotMarkerSize = 0.1;

Show[{ListLogLinearPlot[cosData, PlotRange -> {-1.5, 1.5}, 
   Frame -> True, Joined -> True, PlotStyle -> Blue], 
  ListLogLinearPlot[{pointOfInterest}, PlotRange -> All, 
   PlotStyle -> Red, 
   PlotMarkers -> {Graphics[{Red, Circle[]}], plotMarkerSize}], 
  Graphics[
   Text[Style["This is an\nannotation", 
     FontFamily -> "Arial"], {Log[18.8496], 1.0}, {-1, -1}]]}]

enter image description here

$\endgroup$

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.