0
$\begingroup$

I have a RegionPlot that shows a couple of problems. The first one is that the region that borders the axes is overpassing them, there's a bit of the colour of the region outside the limit of the axes. I would like to know if that's something fixable.

Secondly, in that same plot the same happens to the framed legend, where its background passes through the lines of the frame.

There's the code. I don't know if that's enough to know what happens, if needed, ask for more.

xxx=1.01851;
yyy=0.375881;
sx=0.00421787;
sy=0.00178086;
Covxy=0.000905803;
l = Sqrt[sx^2 + sy^2];
d = MultinormalDistribution[{xxx, 
    yyy}, {{sx*100, Covxy*100}, {Covxy*100, sy*100}}];
sigma1 = 1/(l*100*Sqrt[2*Pi*E]);
sigma2 = 1/(l*100*Sqrt[2*Pi*E^4]);
sigma3 = 1/(l*100*Sqrt[2*Pi*E^9]);

   RegionPlot[{PDF[d, {x, y}] > sigma1, PDF[d, {x, y}] < sigma1, 
  PDF[d, {x, y}] < sigma2, PDF[d, {x, y}] < sigma3}, {x, -2, 
  3}, {y, -2, 3}, 
 PlotStyle -> {RGBColor[1, 0, 1], RGBColor[1, 0.6, 1], 
   RGBColor[1, 0.8, 1.], RGBColor[1, .9, 1]}, 
 PlotRange -> {{-.3, 2.3}, {-1, 1.5}}, BoundaryStyle -> None, 
 Epilog -> {{Green, Point[{xxx, yyy}]}, {Red, Point[{0, 0}]}}, 
 PlotLegends ->
 Placed[Framed[
    SwatchLegend[{RGBColor[1, 0, 1.], RGBColor[1, 0.6, 1], 
      RGBColor[1, 0.8, 1.], RGBColor[1, .9, 1]}, {"1\[Sigma]", 
      "2\[Sigma]", "3\[Sigma]", "4\[Sigma]"}], 
    Background -> White], {.955, .075}]]

It shows this: As you can see, the left and top edges seems to be overpassed by a small region. Also the legend looks wierd

Sorry for my English, it's not my first language. Also it's my first post so if there's something to be fixed, please tell me.

There it is a better look

$\endgroup$
6
  • $\begingroup$ Welcome to the Mathematica Stack Exchange. Please copy your own example from this post to a notebook with a fresh kernel and see what values you still need to provide for this to run. Thanks. $\endgroup$
    – Syed
    Commented Nov 17, 2023 at 1:18
  • $\begingroup$ Can you include the definitions of d, sigma1, ... so we can run your code? $\endgroup$
    – MarcoB
    Commented Nov 17, 2023 at 1:19
  • $\begingroup$ I don't see "the region that borders the axes is overpassing them, there's a bit of the colour of the region outside the limit of the axes" in the picture posted. Can you mark the problem areas by hand and post a picture? $\endgroup$
    – kglr
    Commented Nov 17, 2023 at 9:33
  • 1
    $\begingroup$ Please add the output of $Version to your post. Thanks. $\endgroup$
    – Syed
    Commented Nov 17, 2023 at 10:07
  • $\begingroup$ @kglr It's actually pretty small, and now seeing the picture in this website does not seems to be that big as when I was seeing it in my Photos app. But I see that the legend looks kind of akward though. $\endgroup$ Commented Nov 18, 2023 at 10:26

1 Answer 1

2
$\begingroup$

Does this give the expected result?

I changed PlotRange to All and the placement of PlotLegends to {.9, ,2}

RegionPlot[{PDF[d, {x, y}] > sigma1, PDF[d, {x, y}] < sigma1, 
  PDF[d, {x, y}] < sigma2, PDF[d, {x, y}] < sigma3}, {x, -2, 
  3}, {y, -2, 3}, 
 PlotStyle -> {RGBColor[1, 0, 1], RGBColor[1, 0.6, 1], 
   RGBColor[1, 0.8, 1.], RGBColor[1, .9, 1]}, PlotRange -> All, 
 BoundaryStyle -> None, 
 Epilog -> {{Green, Point[{xxx, yyy}]}, {Red, Point[{0, 0}]}}, 
 PlotLegends -> 
  Placed[Framed[
    SwatchLegend[{RGBColor[1, 0, 1.], RGBColor[1, 0.6, 1], 
      RGBColor[1, 0.8, 1.], RGBColor[1, .9, 1]}, {"1\[Sigma]", 
      "2\[Sigma]", "3\[Sigma]", "4\[Sigma]"}], 
    Background -> White], {.9, .2}]]

enter image description here

You can also try PlotRangePadding (consult documentation for its syntax)

RegionPlot[{PDF[d, {x, y}] > sigma1, PDF[d, {x, y}] < sigma1, 
  PDF[d, {x, y}] < sigma2, PDF[d, {x, y}] < sigma3}, {x, -2, 
  3}, {y, -2, 3}, 
 PlotStyle -> {RGBColor[1, 0, 1], RGBColor[1, 0.6, 1], 
   RGBColor[1, 0.8, 1.], RGBColor[1, .9, 1]}, PlotRange -> All,
 PlotRangePadding -> None,
 BoundaryStyle -> None,
 Epilog -> {{Green, Point[{xxx, yyy}]}, {Red, Point[{0, 0}]}}, 
 PlotLegends -> 
  Placed[Framed[
    SwatchLegend[{RGBColor[1, 0, 1.], RGBColor[1, 0.6, 1], 
      RGBColor[1, 0.8, 1.], RGBColor[1, .9, 1]}, {"1\[Sigma]", 
      "2\[Sigma]", "3\[Sigma]", "4\[Sigma]"}], 
    Background -> White], {.9, .2}]]

enter image description here

$\endgroup$
3
  • $\begingroup$ Not really, now this gives me a plot with the region near the edges being white, I mean, there's like a wide white line just beside the edges, its like the opposite of what was happening haha. Also, the legend stays the same. But thanks for trying. $\endgroup$ Commented Nov 17, 2023 at 9:17
  • $\begingroup$ Oh I think that's better, it fixes the issue. Thank you so much. $\endgroup$ Commented Nov 18, 2023 at 10:34
  • $\begingroup$ Thanks for the accept, I'm glad that I could help $\endgroup$
    – eldo
    Commented Nov 18, 2023 at 10:35

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.