1
$\begingroup$

For the RegionPlot command, the code PlotLegends -> {Style[,],Style[,]} generates plot legend outside the graphic. But I need to generate the legend inside the graphic, precisely, on the domain $y < f(x)$ there must be corresponding legend.

How to do that?

For concreteness, I want the following (see picture).enter image description here

Each of legends is located inside the corresponding domain. The code corresponding to picture is

RegionPlot[{y > -6 - 3/2*x, y > -12 + x/4}, {x, -20, 10}, {y, -20, 
  20}, PlotLegends -> {Style["Lifetime", FontSize -> 20], 
   Style["Angular approximation", FontSize -> 20]}, 
 FrameLabel -> {Subscript[Log, 10][
    "\!\(\*SubscriptBox[\(m\), \(\[Theta]\)]\)"/"eV"], 
   Subscript[Log, 10][
    "\!\(\*SubscriptBox[\(g\), \(\[Gamma]\)]\)"/
     "\!\(\*SuperscriptBox[\(GeV\), \(-1\)]\)"]}, 
 RotateLabel -> False, LabelStyle -> (FontSize -> 15), Frame -> True]
$\endgroup$
4
$\begingroup$

Use Placed

RegionPlot[
 {x^2 < y^3 + 1, y^2 < x^3 + 1},
 {x, -2, 5}, {y, -2, 5},
 PlotLegends -> Placed["Expressions", {0.15, 0.08}]]

enter image description here

EDIT: If instead of PlotLegends you want to label the regions then use:

Show[
 RegionPlot[{x^2 < y^3 + 1, y^2 < x^3 + 1}, {x, -2, 5}, {y, -2, 5},
  PlotStyle -> {{Blue, Opacity[0.25]}, {Yellow, Opacity[0.25]}}],
 Graphics[{
   Text[Style[
     ToString[x^2 < y^3 + 1, TraditionalForm],
     Bold, 16], {0, 3}],
   Text[Style[
     ToString[y^2 < x^3 + 1, TraditionalForm],
     Bold, 16], {3, 0}]}]]

enter image description here

$\endgroup$
  • $\begingroup$ Thank You! But I need slightly another thing: precisely, I want $x^{2} < y^{3}+1$ to be located on the blue domain, while $y^{2} < x^{3} +1$ to be located on the yellow domain. Independently on precise domain. $\endgroup$ – John Taylor May 4 '17 at 15:28
  • 1
    $\begingroup$ Add PlotStyle -> {{Blue, Opacity[0.25]}, {Yellow, Opacity[0.25]}}. When asking questions include your code and any constraints. $\endgroup$ – Bob Hanlon May 4 '17 at 15:38
  • $\begingroup$ But does this move the "$x^{2} < y^{3}+1$" legend on the blue domain? $\endgroup$ – John Taylor May 4 '17 at 15:55
3
$\begingroup$
Legended[RegionPlot[{x^2 < y^3 + 1, y^2 < x^3 + 1}, {x, -2, 5}, {y, -2, 5}], 
 {Placed[SwatchLegend[{ColorData[1, "ColorList"][[1]]}, 
        {TraditionalForm[x^2 < y^3 + 1]}], {0.2, 0.7}], 
  Placed[SwatchLegend[{ColorData[1, "ColorList"][[2]]}, 
        {TraditionalForm[y^2 < x^3 + 1]}], {0.7, 0.2}]}]

Mathematica graphics

$\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.