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

2 Answers 2

5
$\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$
8
  • $\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$ Commented May 4, 2017 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$ Commented May 4, 2017 at 15:38
  • $\begingroup$ But does this move the "$x^{2} < y^{3}+1$" legend on the blue domain? $\endgroup$ Commented May 4, 2017 at 15:55
  • $\begingroup$ I only have one region and still want to get the legend. I tried the following, but why the legend does not show up? RegionPlot[x^2 < y^3 + 1 && y^2 < x^3 + 1, {x, -2, 5}, {y, -2, 5}, PlotLegends -> Placed["Expressions", {0.15, 0.08}]] $\endgroup$ Commented May 3, 2021 at 1:59
  • $\begingroup$ @DavidXiaoyuXu - For any plot function, if there is a single expression to be plotted, PlotLegends -> "Expressions" will not produce a legend. Try RegionPlot[x^2 < y^3 + 1 && y^2 < x^3 + 1, {x, -2, 5}, {y, -2, 5}, PlotLegends -> Placed[Style["x^2<y^3+1&&\ny^2<x^3+1", Bold], {.8, .8}]] $\endgroup$ Commented May 3, 2021 at 2:16
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$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.