2
$\begingroup$

I would like to plot a partially filled/shaded ellipse. The code below shades the whole ellipse. However, I only want to shade the part of the ellipse to the right of the vertical line where x > cutscore.

Needs["MultivariateStatistics`"]

cutscore = 0.5; 
data1 = RandomVariate[MultinormalDistribution[{0, 0}, {{1, 0.6}, {0.6, 1}}], 500];
ellipse1 = EllipsoidQuantile[data1, 0.5];
e1 = Graphics[ellipse1];
line1 = Graphics[{Line[{{cutscore, -1.3}, {0.5, 1.5}}]}];
show1SEL = Show[e1, line1, Axes -> {True, False}, AxesOrigin -> {-2, -2}, 
           PlotRange -> {{-2, Automatic}, {-2, Automatic}}];
show1SELfilled = show1SEL /. Line[x_] -> {Green, EdgeForm@Thin, FaceForm[Opacity@.2], Polygon[x]}
$\endgroup$
  • $\begingroup$ You haven't defined EllipsoidQuantile. This is related: Coloring a shape according to a function. $\endgroup$ – Artes Aug 28 '14 at 22:50
  • $\begingroup$ EllipsoidQuantile is defined in "MultivariateStatistics`", now added. $\endgroup$ – Chris Degnen Aug 28 '14 at 23:43
6
$\begingroup$
Needs["MultivariateStatistics`"]

cutscore = 0.5;
data1 =
  RandomVariate[
   MultinormalDistribution[
    {0, 0}, {{1, 0.6}, {0.6, 1}}],
   500];
ellipse1 = EllipsoidQuantile[data1, 0.5];
e1 = Graphics[ellipse1];
line1 = Graphics[{
    Line[{{cutscore, -1.3}, {cutscore, 1.5}}]}];

show1SELfilled = Show[e1, line1,
  Graphics[{
    LightBlue,
    Polygon[
     DeleteCases[
      Cases[e1, Line[pts_] :> pts, Infinity][[1]],
      {_?(# < cutscore &), _}]]}],
  Axes -> {True, False},
  AxesOrigin -> {-1.5, -1.5},
  PlotRange -> {{-1.5, Automatic}, {-1.5, Automatic}}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks Bob, This is exactly what I needed - Dan Segall $\endgroup$ – Dan Segall Aug 29 '14 at 13:41

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.