0
$\begingroup$

I have a Plot[...] of a system of linear equations and a function graphicsPoint[...] that generates a graphics point to show where the lines intersect. The Tooltip[...] version of graphicsPoint[...] at the intersection point works but a Labeled[...] version is preferred which should be placed next to but above the graphics point.

I am aware of using Callout[...] but this is not preferred because it needs to wrap one of the equations which are generated by another function and would greatly complicate the code for that function. However if I am misunderstanding it's use and can be done without wrapping one of the equations I am open to it.

Below are two versions of the graphicsPoint[...].

Here is the desired plot of system of two linear equations. This works...

plot = Plot[{(1 - x)/2, -2 - 3 x}, {x, -3, 1}, PlotRange -> {-1, 3}, 
  PlotStyle -> Thick, PlotLabels -> {y == (1 - x)/2, y == -2 - 3 x}, 
  AxesLabel -> {x, y}, ImageSize -> {Automatic, 200}]

This tooltip version of graphicsPoint[...] works alone and when combined with plot=Plot[...] using Show[plot,graphicsPoint[...]]...

graphicsPoint[loc_ : {0, 0}, color_ : Red, size_ : 8] := 
  Block[{graphic},
   graphic = If[Length[loc] == 2, Graphics, Graphics3D];
   graphic[{
     color, AbsolutePointSize[size], Tooltip[
      Point[loc], loc, 
      TooltipStyle -> {22, Black, Background -> LightBlue}
      ]
     }]];
graphicsPoint[{-1, 3}]
Show[plot, graphicsPoint[{-1, 3}]]

graphicsPoint2[...] is the attempted refactor of said graphics point replacing Tooltip[...] with Labeled[...]. It only halfway works alone as it does label the point but far below it at the very bottom of the bounding box rendering it almost useless. It creates an error when combined using Show Also note that the BaseStyle for Labeled[...,BaseStyle] is mostly ignored by Mathematica...

graphicsPoint2[loc_ : {0, 0}, color_ : Red, size_ : 8] := Block[{fn},
   fn = If[Length[loc] == 2, Graphics, Graphics3D];
   Labeled[
    fn[{
      color,
      AbsolutePointSize[size],
      Point[loc]
      }
     ],
    loc, BaseStyle -> {22, Black, Background -> LightBlue}]
   ];

graphicsPoint2[{-1, 3}]
Show[plot, graphicsPoint2[{-1, 3}]]
$\endgroup$

1 Answer 1

1
$\begingroup$

Instead of Labeled, use Text

Clear["Global`*"];

eqns = {(1 - x)/2, -2 - 3 x};

pt = {x, eqns[[1]]} /.
  Solve[Equal @@ eqns, x, Reals][[1]]

(* {-1, 1} *)

plot = Plot[eqns, {x, -3, 1}, PlotRange -> {-1, 3}, PlotStyle -> Thick, 
   PlotLabels -> {y == (1 - x)/2, y == -2 - 3 x}, AxesLabel -> {x, y}, 
   ImageSize -> {Automatic, 200}];

graphicsPoint[loc_ : {0, 0}, color_ : Red, size_ : 8] :=
  Block[{graphic},
   graphic = If[Length[loc] == 2, Graphics, Graphics3D];
   graphic[{
     Text[loc, loc, {-1.5, -2}],
     color,
     AbsolutePointSize[size],
     Tooltip[Point[loc], loc,
      TooltipStyle -> {22, Black, Background -> LightBlue}]}]];

Show[plot, graphicsPoint[pt]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks for the input. It looks like you had to manually (by trial and error I suppose) derive location {-1.5, -2} for text: Text[loc, loc, {-1.5, -2}]. I was hoping to avoid that. That is why I was hoping to use a function similar to Tooltip that automatically locates the label near the point of interest and includes special options (like Top) that refines location. $\endgroup$ Jul 7, 2020 at 4:58

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.