Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Tag Info

Hot answers tagged filling

42

The following solution is hacky work-around to overcome the lack of proper pattern directives. I don't like it 100%, but still it is usable. Solution The idea is simple. If you see FilledCurve documentation, it supports an object with holes: So what if you put a huge enough rectangle as an outer boundary? Then, your polygon becomes a hole and you can see ...

29

How about this? bankerPlot[data_] := ListLinePlot[ data, AxesOrigin -> {0, 0}, Prolog -> Polygon[Join[data, Reverse[data.DiagonalMatrix[{1, 0}]]], VertexColors -> Join[ Blend[{Black, Blue}, #] & /@ Normalize[data[[All, 2]], Max], ConstantArray[Black, Length[data]] ] ], PlotStyle -> White, Background -> ...

27

You have a (or more) curves. If you don't use PolarPlot you could use ParametricPlot instead but you would have to make the transformation from polar coordinates by yourself. Knowing this, you could think about what your functions mean. For instance 2 (1 - Cos[phi]) is just the radius of your curve for a given phi. If you want to draw the region outside ...

26

An alternative is to use Piecewise as follows Plot[{Sin[x], Piecewise[{{Sin[x], -Pi <= x <= Pi}}, _]}, {x, -2 Pi, 2 Pi}, Filling -> {2 -> {Axis, Yellow}}, PlotStyle -> {Green, Directive[Red, Thick]}] which gives Or Use Show to superimpose two variants (the second one with your choice of the variable bounds -- -Pi and 2Pi in the ...

25

ragfield's solution is a good one that can easily be extended to arbitrarily complicated polygons if we create an inPolyQ function using winding numbers. Here is a complicated polygon (the points only) from Mathematica's example data. poly = Rescale[ExampleData[{"Statistics", "WesternUgandaBorder"}]]; This function determines whether a point is in the ...

25

This is a simple little hack that will replace the polygons created by your Filling command with a set of random points. By default I'm scaling the number of random points by the number of points in the polygon, so that the density of points stays relatively constant. dotFillPlot[plot_, ndots_: 5] := plot // Normal // ReplaceAll[ Polygon[a__] :> ...

23

Update: Using MeshFunctions and Mesh in RegionPlot: RegionPlot[Evaluate[RegionRegionProperty[Rationalize /@ blob, {x, y}, "FastDescription"][[1, 2]]], {x, -3, 3}, {y, -3, 3}, Mesh -> 50, MeshFunctions -> {#1 + #2 &, #1 - #2 &}, MeshStyle -> White, PlotStyle -> Directive[{Thick, Blue}]] With settings MeshStyle -> GrayLevel[....

22

For plotting a continuous function, you could do something like this: f[x_] := (1 + Cos[5 x]/2) Sin[x] ParametricPlot[{x, f[x] y}, {x, 0, Pi}, {y, 0, 1}, PlotPoints -> 30, ColorFunction -> (Blend[{Black, Blue, White}, #2] &), Mesh -> None, AspectRatio -> 1/GoldenRatio] Edit This method can be used for plotting a list of points as ...

22

I was sure Histogram can be modified to have the hatching style. Little late but what about this! g[{{xmin_, xmax_}, {ymin_, ymax_}}, ___] := Module[{yval, line}, yval = Range[ymin, ymax, 15]; line = Line /@ Transpose@{Most@({xmin, #} & /@ yval),Rest@({xmax, #} & /@ yval)}; {FaceForm[White],Polygon[{{xmin, ymin}, {xmax, ymin}, {xmax, ymax}, {...

21

Even if Filling were an option in PolarPlot, you won't be able to create such a plot because for 2D graphics, Filling just blindly fills along the y-axis, whereas you need to check for an inequality here. That said, here's another approach that's in the same spirit as halirutan's, but you don't have to convert to Cartesian, etc. eqns[t_] := { Sqrt[2 Cos[t]...

19

Something like this? RegionPlot[y < 1/x && y + 0.3 > 1/(x + 0.3) , {x, 0, 3}, {y, 0, 4}, AxesOrigin -> {0, 0}, Frame -> False, Axes -> Automatic, Mesh -> 20, MeshFunctions -> {#1 - #2 &}, BoundaryStyle -> None]~Show~ Plot[1/x, {x, 0, 3}] You can add PlotStyle -> Transparent to the RegionPlot if you don't ...

18

Here's a modification of Heike's ParametricPlot approach, using textures instead of ColorFunction. pts1 = RandomReal[10, 100]; interpol = Interpolation[pts1, InterpolationOrder -> 1]; ParametricPlot[{u, interpol[u] v}, {u, 1, Length[pts1]}, {v, 0, 1}, Mesh -> None, AspectRatio -> 1/GoldenRatio, TextureCoordinateFunction -> ({#1, #2} &),...

18

Plot[{0.8333*H + 16.928*H^0.25 - 85, Max[-9 + Max[H - 80, 0], H - 80]}, {H, 0, 700}, PlotStyle -> {Directive[Black, Thick], Black}, Filling -> {1 -> {{2}, {Yellow, Transparent}}}]

17

Just another way: << VectorAnalysis; {rho, t, z} = CoordinatesFromCartesian[{x, y, z}, Cylindrical] Quiet@Show[ PolarPlot[{ Sqrt[2 Cos@t], 2 (1 - Cos@t)}, {t, -Pi, Pi}], RegionPlot[ Sqrt[2 Cos@t] > rho > 2 (1 - Cos@t), {x, 0, 2}, {y, -1, 1}]]

17

Mathematica's graphics language lacks a clipping primitive. However, you can sometimes simulate the same appearance using the sophisticated visualization functions. RegionPlot[((0 <= x <= .5) && (0 <= y <= 1 + x)) || ((.5 < x <= 1) && 0 <= y <= 2 - x), {x, -1, 2}, {y, -1, 2}, Mesh -> 20, MeshFunctions -> ...

16

This is a variant of Argento's answer with the blend on a rectangle in the background rather than creating a polygon that matches the data. bankerData = Transpose[{Range, Accumulate[RandomReal[{-1, 1}, 100]] + 10}]; ListLinePlot[bankerData, Frame -> True, Background -> Black, AxesOrigin -> {0, 0}, PlotRange -> {{1, 100}, {0, 20}}, ...

16

Yet another way. It's similar to belisarius's solutions but doesn't require an inverse coordinate transformation Show[ PolarPlot[{Sqrt[2 Abs[Cos[t]]], 2 (1 - Cos[t])}, {t, -\[Pi], \[Pi]}], RegionPlot[4 (1 - Cos[t])^2 < r^2 < 2 Cos[t], {r, 0, 3}, {t, -Pi, Pi}, PlotPoints -> 30] /. GraphicsComplex[a_, b__] :> GraphicsComplex[#1 {Cos[#2], ...

16

I would do something like: t = RandomVariate[NormalDistribution[0, 1], 10000]; a = Histogram[t, 30, ChartStyle -> White]; b = Histogram[t, 30, ChartElements -> Graphics[{Black, Line[{{0, 0}, {1, 1}}]}]]; Show[a, b]

15

You can parameterize your polar functions on to discs, and then shade appropriately. ρ[t_] := Sqrt[2 Cos[t]]; σ[t_] := 2 (1 - Cos[t]); ParametricPlot[{{r Cos[t] ρ[t], r Sin[t] ρ[t]}, {r Cos[t] σ[t], r Sin[t] σ[t]}}, {t, -π, π}, {r, 0, 1}, PlotStyle -> {{Opacity[.5], Red}, {Opacity, White}}, Mesh -> None, PlotRange -> All]

15

I have distilled a minimal dataset reproducing the problem: data = {{{45.904, 227.46}, {46.012, 222.72}, {46.076, 215.51}, {46.107, 206.26}, {46.119, 196.15}, {46.119, 186.97}, {46.118, 178.5}, {46.104, 168.16}, {46.079, 156.43}}, {{45.912, 212.72}, {45.976, 205.51}, {46.007, 196.26}, {46.019, 186.15}, {46.019`, ...

14

How about dt = Pi/99; pts = Join[ Table[2 (1 - Cos[t]) {Cos[t], Sin[t]}, {t, 0, -Pi/3 + dt, -dt}], Table[Sqrt[2 Cos[t]] {Cos[t], Sin[t]}, {t, -Pi/3, Pi/3, dt}], Table[2 (1 - Cos[t]) {Cos[t], Sin[t]}, {t, Pi/3, dt, -dt}] ]; PolarPlot[{Sqrt[2 Cos[t]], 2 (1 - Cos[t])}, {t, -\[Pi], \[Pi]}, Prolog -> {LightGray, Polygon[pts]}, ...

14

Here's a meager attempt that will soon be humiliated by Heike's answer. ;-) g = PolarPlot[Evaluate@{{1, -1} Sqrt[2 Cos[t]], 2 (1 - Cos[t])}, {t, -\[Pi], \[Pi]}]; Graphics[{ {Pink, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, Thread@{{White, Green, Blue}, Reverse@Cases[g, Line[x__] :> Polygon[x], ∞]} }]; Show[g, %, g] Seeing as I ...

14

The FilledCurve approach in the accepted answer by @Yu-Sung Chang is very interesting, so I tried to make my own version of it. I defined the whole thing as a function that accepts graphics directives for the objects to be masked (backgroundDirectives - e.g., the fill pattern or image), and an arbitrary polygon as the mask. This includes Polygon with several ...

14

Here's happy: Plot[{Sin[9 \[Pi] t/10], 2 Sin[7 \[Pi] t/10]}, {t, 0, 20}, AspectRatio -> 0.2, AxesLabel -> {"weeks", "affection"}, Filling -> {1 -> {Axis, {None, Green}}, 1 -> {{2}, White}}]

14

Here is extended version of PlatoManiac's solution which allows changing of the direction of the hatching and also tuning the distance between hatches: g[step_?NumberQ][{{xmin_, xmax_}, {ymin_, ymax_}}, ___] := Module[{yval, lines, xstart, xend}, yval = Range[ymin, ymax, Abs[step]]; If[step > 0, {xstart, xend} = {xmin, xmax}, {xstart, xend} = {...

13

im = Binarize@Import["http://i.stack.imgur.com/ZDeYq.jpg"]; Colorize[MorphologicalComponents@im, ColorRules -> {1 -> Red, 2 -> Yellow, 3 -> Blue, 4 -> Green}]

13

Changing the order of lists restore the filling x = {{10.5, 8.5}, {20, 15.3, 11.9, 8.8}, {16.5, 12.5, 9.2, 6.5}}; ListLogPlot[x, Joined -> True, PlotRange -> {{1, 5}, All}, Filling -> {1 -> {{3}, Brown}, 2 -> {{3}, Gray}}]

12

Alternatively, you can use the +/- option of Filling Plot[{x + 7, 9 - x^2}, {x, 0, 1.5}, Filling -> {1 -> {{2}, {LightBlue, White}}}]

12

Graphics[{ Yellow, FilledCurve[{BSplineCurve /@ {pts1, pts4, Reverse@pts2, pts3}}], Green, Line[Join[pts1, pts4, Reverse@pts2, pts3]], Red, Point[Join[pts1, pts2, pts3, pts4]] }]

11

Here is another method that uses the more general gradient background construction I posted as an answer to "How can I set different opacity values for the background of a ListPlot". This answer is rather late, but I thought it's a good example of how else to use the simple option Prolog -> gradientBackground to create a gradient background: ...

Only top voted, non community-wiki answers of a minimum length are eligible