6
$\begingroup$

How can I fill the inverted region of this? I want to fill the region outside of this shape t instead.

ListLinePlot[{{-1, 1}, {1, 1}, {10,
10}, {10, -10}, {1, -1}, {-1, -1}, {-10, -10}, {-10, 10}, {-1, 1}},
PlotStyle -> Directive[Red, Dashed, Thickness[0.008]],
Filling -> {1 -> Axis}, FillingStyle -> Lighter[Gray, 0.85]]
$\endgroup$
5
$\begingroup$
pts = {{-1, 1}, {1, 1}, {10, 
   10}, {10, -10}, {1, -1}, {-1, -1}, {-10, -10}, {-10, 10}, {-1, 1}}

Using Prolog:

ListLinePlot[pts, PlotStyle -> Directive[Red, Dashed, Thickness[0.008]]
 , Filling -> {1 -> Axis}, FillingStyle -> Lighter[White, 0.85]
 , Prolog -> {GrayLevel[0.9]
   (*, Rectangle[{-10,-10},{10,10}]*)
   , Rectangle @@ {
       {
        Min[#[[All, 1]]], Min[#[[All, 2]]]}
       , {Max[#[[All, 1]]], Max[#[[All, 2]]]
        }
       } &@pts
   }
 ]

enter image description here

$\endgroup$
5
$\begingroup$
  • Use RegionDifference to construct the outer region.
pts = {{-1, 1}, {1, 1}, {10, 
    10}, {10, -10}, {1, -1}, {-1, -1}, {-10, -10}, {-10, 10}, {-1, 1}};
outreg = TransformedRegion[Rectangle @@ CoordinateBoundingBox[pts], 
   ScalingTransform[{1.2, 1.2}, Mean[pts]]];
inreg = Polygon[pts];
clip = RegionDifference[outreg, inreg];
Graphics[{{Lighter[Gray, 0.5], 
   clip}, {EdgeForm[Directive[Red, Dashed, Thickness[0.008]]], 
   FaceForm[], inreg}}, AspectRatio -> 1/GoldenRatio, Axes -> True]

enter image description here

  • Use Polygon[outpts -> {inpts}] to get holes.
pts = {{9, 11}, {11, 11}, {20, 15}, {9, -5}, {11, 9}, {9, 9}, {-10, 
    0}, {0, 20}, {9, 11}};
inpts = Most@pts;
{{xmin, xmax}, {ymin, ymax}} = {MinMax[pts[[;; , 1]]], 
   MinMax[pts[[;; , 2]]]};
outpts = {{xmin, ymin}, {xmax, ymin}, {xmax, ymax}, {xmin, ymax}};
clip = Polygon[outpts -> {inpts}];
Graphics[{Lighter[Gray, 0.5], clip, 
  Directive[Red, Dashed, Thickness[0.008]], Line[pts]}, 
 AspectRatio -> 1/GoldenRatio, Axes -> True, PlotRangePadding -> .8]

enter image description here

$\endgroup$
4
$\begingroup$

Fill with white and make the background gray:

ListLinePlot[{{-1, 1}, {1, 1}, {10, 
   10}, {10, -10}, {1, -1}, {-1, -1}, {-10, -10}, {-10, 10}, {-1, 1}},
  PlotStyle -> Directive[Red, Dashed, Thickness[0.008]], 
 Filling -> {1 -> Axis}, FillingStyle -> White, 
 Background -> Lighter[Gray, 0.85]]

enter image description here

$\endgroup$
4
$\begingroup$
coords = {{-1, 1}, {1, 1}, {10, 10}, {10, -10}, {1, -1}, {-1, -1}, 
  {-10, -10}, {-10, 10}, {-1, 1}};

Graphics[{Lighter[Gray, 0.5], Rectangle @@ (Scaled /@ {{0, 0}, {1, 1}}), 
    EdgeForm[{Red, Dashed, AbsoluteThickness[3]}], White, Polygon @ coords}, 
  AspectRatio -> 1/GoldenRatio, Axes -> True]

enter image description here

Graphics[{Directive[Red, Dashed, AbsoluteThickness[4]], Line @ coords, 
  Lighter[Gray, 0.5], FilledCurve[Line /@ 
    {Scaled /@ {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}, coords}]}, 
 AspectRatio -> 1/GoldenRatio, Axes -> True]

enter image description here

$\endgroup$
0
$\begingroup$

The even-odd rule for FilledCurve can be used:

Module[{shape = {Line[{{-1, 1}, {1, 1}, {10, 10}, {10, -10}, {1, -1},
       {-1, -1}, {-10, -10}, {-10, 10}, {-1, 1}}]},
  universe = {Line[{{-100, 100}, {100, 100}, {100, -100}, {-100, -100},
       {-100, 100}}]}, 
  bounds = {{-10.5, 10.5}, {-11, 11}}}, 
 Graphics[{Lighter[Gray, .75], FilledCurve[{shape, universe}], Dashed,
    Red, Thickness[.008], JoinedCurve[shape]}, 
  AspectRatio -> (1/GoldenRatio), Axes -> True, PlotRange -> bounds, 
  ImageSize -> 360]]

enter image description here

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