3
$\begingroup$

I'm running into some problems plotting 2D Ellipsoids with non-diagonal weight matrices -- they are not centered where they are supposed to be. I'm not sure exactly what the problem is, it only seems to happen when the numbers are $\gg1$. The ellipse can even change positions if you change the plot range. The same thing happens with both Epilog and Show.

I am using version 10.0.2.0. Thanks for any help or workarounds. I am trying to plot ellipses corresponding to confidence regions on top of density plots, so the scales of the axes matter to me.

Row[
    Plot[x, {x, -500, 500}, 
        Epilog -> {Opacity[0], EdgeForm[Thick], 
            Ellipsoid[{0, 0}, 
                RotationMatrix[#].{{40000, 0}, {0, 20000}}.RotationMatrix[-#]]}, 
        AspectRatio -> 1, ImageSize -> 300
    ] & /@ {0, 10^-8, π/4}
]

enter image description here

$\endgroup$

1 Answer 1

5
$\begingroup$

The second argument of Ellipse seems to need to be a vector (and not a matrix). In any case, try rotating the object. You'll also want to change the position ({0,0} below) to get it centered where you want. Something like:

Row[Plot[x, {x, -500, 500}, 
    Epilog -> {Opacity[0], EdgeForm[Thick], 
      Rotate[Ellipsoid[{0, 0}, {400, 200}], #]}, AspectRatio -> 1, 
    ImageSize -> 300] & /@ {0, \[Pi]/4}]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks, good fix. "The second argument of Ellipse seems to need to be a vector" -- the docs are clear it can be a matrix, I guess you mean it needs to be a vector to plot properly. They must have different plotting code for each case, and they also check to see if the matrix is diagonal or not. $\endgroup$
    – Ian Hincks
    Commented May 12, 2016 at 16:04
  • 1
    $\begingroup$ I think there is may be some kind of bug. Consider Plot[x, {x, -500, 500}, Epilog -> {Rotate[ Ellipsoid[{0, 0}, {{4000, 0}, {0, 2000}}], \[Pi]/4]}, AspectRatio -> 1] When I plot this, and move the cursor up and down, the position of the ellipse seems to jump around. $\endgroup$
    – bill s
    Commented May 12, 2016 at 16:11
  • $\begingroup$ I have noticed weird stuff like this too! I was just not sure how to explain how to reproduce it, or if it was just another of the many small GUI problems with Mathematica in linux. $\endgroup$
    – Ian Hincks
    Commented May 12, 2016 at 16:14
  • $\begingroup$ To make your answer more general (in most practical cases the rotation matrix would not be explicitly there), something like makeEllipse[p_, mat_] := Module[{d, v}, {d, v} = Eigensystem[mat]; Rotate[Ellipsoid[p, Sqrt@d], ArcTan @@ (First@v)]] would be good. Thanks again, I will accept. $\endgroup$
    – Ian Hincks
    Commented May 12, 2016 at 16:15

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.