2
$\begingroup$

Is it possible to automatically label boundaries of a RegionPlot in a similar style to PlotLabels by the equality that describes them. Ideally even splitting any Or statement to the relevant part that holds at that boundary. So that for example in the plot below

RegionPlot[{x > y || x^2 + y^2 < 1, y > 2 x || x^2 + y^2 < 2}, {x, -2,
   2}, {y, -2, 2}]

The straight lines have labels "x = y" and "y = 2 x" and the round parts "x^2 + y^2 = 1" and "x^2 + y^2 = 2".

enter image description here

$\endgroup$
2
$\begingroup$

1. Manually adjust the positions and offsets in Arrowheads and Text to place the labels on the boundary curves:

RegionPlot[{x > y || x^2 + y^2 < 1, y > 2 x || x^2 + y^2 < 2}, {x, -2, 2}, {y, -2, 2}, 
  BoundaryStyle -> 
    {2 ->  Arrowheads[{{Automatic, .75, 
        Graphics[{Text[Style[ToString[x^2 + y^2 == 2, TraditionalForm], Black,  16],
          {0, 0}, {0, -2}, {-1, 0}]}]}, 
       {Automatic, .53, 
        Graphics[{Text[Style[ToString[y == 2 x, TraditionalForm], Black, 16], 
          {.5, 0}, {0, 1}, {-1, 0}]}]}}], 
    1 -> Arrowheads[{{Automatic, .25, 
        Graphics[{Text[Style[ToString[x^2 + y^2 == 1, TraditionalForm], Black,  16], 
         {0, 0}, {0, 2}, {1, 0}]}]}, 
       {Automatic, .1, 
        Graphics[{Text[Style[ToString[y == x, TraditionalForm], Black, 16], 
         {.5, 0}, {0, 1}, {1, 0}]}]}}]}] /. Line -> Arrow

enter image description here

2. Use ListPlot with Callouts and Show with RegionPlot output:

labels = Style[#, 16]& /@ TraditionalForm /@ 
    {y == x, x^2 + y^2 == 1, y == 2 x, x^2 + y^2 == 2};

points = {{-1.5, -1.5}, {-.75, Sqrt[1 - .75^2]}, {.75, 1.5}, {.85, -Sqrt[2 - .85^2]}};

rp =  RegionPlot[{x > y || x^2 + y^2 < 1,  y > 2 x || x^2 + y^2 < 2}, 
     {x, -2, 2}, {y, -2, 2}];


Show[rp, ListPlot[MapThread[Callout, {points, labels}]]]

enter image description here

3. Interactively position the labels using LocatorPane:

DynamicModule[{pts = points}, LocatorPane[Dynamic[pts], rp, Appearance -> labels]]

enter image description here

| improve this answer | |
$\endgroup$

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.