Hot answers tagged

17

You can post-process ParametricPlot output to change Line to FilledCurve: ParametricPlot[{(1 - Cos[2 π s]) Sin[2 π s], Cos[2 π s] (Sin[2 π s] + 1)}, {s, 0, 1}, Axes -> False, PlotStyle -> Black] /. l_Line :> FilledCurve[l] Use the replacement rule l_Line :> {Opacity[1.], FilledCurve[l]} to get We get the same result if we use a rule ...


13

f1h = HoldForm[10 - Sqrt[10^2 - x^2]]; f1 = f1h // ReleaseHold; f2h = HoldForm[5 - Sqrt[5^2 - (x - 5)^2]]; f2 = f2h // ReleaseHold; f3h = HoldForm[5 + Sqrt[5^2 - (x - 5)^2]]; f3 = f3h // ReleaseHold; The x values for the curve intersections are {x1, x2} = x /. Solve[f1 == #, x][[1]] & /@ {f2, f3}; The point coordinates for the curve intersections ...


12

Here's an adaptation of m_goldberg's answer that uses a single plot for his example: Plot[ { c2[x], ConditionalExpression[c1[x], x<.7], ConditionalExpression[c1[x], x>.7] }, {x, 0,1}, PlotStyle->{Red, Blue, Blue}, Filling->{2->{Axis, LightBlue}, 1->{{3}, LightBlue}} ]


10

One simple way to visualize complicated regions in mathematica disk1 = Region[Disk[{5, 5}, 5]] disk2 = Region[Disk[{0, 10}, 10]] disk3 = Region[Disk[{10, 0}, 10]] result = Region[ RegionUnion[RegionDifference[disk1, disk3], RegionDifference[disk1, disk2]]]


9

Update: You can use a single ParametricPlot with the options MeshFunctions and Mesh to get the same result: ParametricPlot[Evaluate[{ffA[x, #] v + (1 - v) ffB[x, #], x} & /@ Range[4]], {x, -10, 10}, {v, 0, 1}, PlotRange -> All, PlotRangePadding -> None, BoundaryStyle -> None, Frame -> False, Ticks -> False, MeshFunctions -&...


8

ListLinePlot[Transpose[data1], PlotStyle -> {Directive[Thick, Blue], Directive[Red], Directive[Red]}, Filling -> {2 -> {3}}, FillingStyle -> {Opacity[.25], Pink}, PlotTheme -> "Detailed"]


8

Perhaps you're looking for something like this: Plot[{ ConditionalExpression[x^2, x < 1], ConditionalExpression[x^2, x > 1], ConditionalExpression[2 + 2 x^2, x < 1] }, {x, 0, 2}, Filling -> {1 -> Bottom} ]


7

Here is one way to do what you are asking for. Functions and given point c2[x_] := x^(1/2) c1[x_] := x^3 x0 = .7; Now we make three plots ... p1 = Plot[{c1[x], c2[x]}, {x, 0, 1}, Epilog -> {Blue, Dashed, Line[{{x0, 0}, {x0, 1}}]}] p2 = Plot[c1[x], {x, 0, x0}, Filling -> Bottom] p3 = Plot[{c1[x], c2[x]}, {x, x0, 1}, Filling -> {1 -> {2}}] ....


6

As kglr comments you can use BoundaryStyle -> None to avoid drawing the boundary line entirely. Then if desired you can draw lines with more control using Mesh and MeshStyle: f[t_, r_, a_] := {r*Cos[2 Pi*t]*Sin[Pi*t + 2*Pi*a], r*Sin[4 Pi*t - 2*Pi*a]*Cos[2*Pi*t + 2*Pi*a]}; ff[a_] := ParametricPlot[f[t, r, a], {t, -1, 1}, {r, 0.5, 1}, PlotRange -&...


6

RegionPlot[ x^2 + y^2 < 25 \[And] ((x - 5)^2 + (y + 5)^2 > 100 \[Or] (x + 5)^2 + (y - 5)^2 > 100), {x, -5, 5}, {y, -5, 5}] Or... z[w_] := EuclideanDistance[{x, y}, w {5, -5}]; RegionPlot[ z[0] < 5 \[And] (z[1] > 10 \[Or] z[-1] > 10), {x, -5, 5}, {y, -5, 5}] Or... z[w_] := (a = ({x, y} - 5 {w, -w})).a; RegionPlot[ z[0] < 25 \[...


6

Since Mathematica 12.1 it is possible to do this with HatchFilling: ListPlot[Transpose@Table[{15 - x, 2 Sin[x] + x}, {x, 0, 15, 0.1}], PlotStyle -> Black, Filling -> Bottom, FillingStyle -> {1 -> HatchFilling[-Pi/4], 2 -> HatchFilling[Pi/4]}, Joined -> True] Of course, the hashing can be styled in many ways.


5

Version 12.1 comes with the functions HatchFilling and PatternFilling which make the task much easier: PieChart[{1, 2, 3}, ChartStyle -> {Directive[GrayLevel[.5], HatchFilling["Diagonal"]], Directive[GrayLevel[0], HatchFilling["Horizontal", 2, 7]], Directive[GrayLevel[.7], HatchFilling["Vertical", 5, 10]]}, SectorOrigin -> {Automatic, 1}, ...


5

Since Mathematica 12.1 it is possible to do this with HatchFilling: ListLinePlot[ Table[2 Sin[x] + x, {x, 0, 15, 0.1}], Filling -> Bottom, FillingStyle -> HatchFilling[-Pi/4, 2, 10]] Of course, the hashing can be styled in many ways.


5

You need to interpolate between the two bounding curves. One way to do this is to multiply one of the bounding curves by $t$, multiply the other by $(1-t)$, and create a ParametricPlot running from $t = 0$ to 1. originalplot = ParametricPlot3D[ { {x*Sin[x], x*Cos[x], -(x/3)}, {Sqrt[y]*x*Sin[x], y^2*x*Cos[x], -(x/3)}, {Sqrt[y]*x*Sin[x], y^...


4

Mr.Wizard's provides a good solution. but I strongly reccomend replacing MeshStyle -> Directive[Opacity[1], AbsoluteThickness[3], Red] with MeshStyle -> Directive[Thin, rColor, Opacity[1]] where rColor = RGBColor[0.775, 0.820, 0.900]; which closely matches the bluish color Mathematica uses fill regions. However, you might also consider an ...


4

One easy way is to let ParametricPlot linearly interpolate between the two curves: f1 = {x*Sin[x], x*Cos[x], -((2*x)/3)}; f2 = {1.15*x*Sin[x], 1.15*x*Cos[x], -((2*x)/3)}; ParametricPlot3D[{ lambda f1 + (1 - lambda) f2 }, {x, 0, (11/4)*Pi}, {lambda, 0, 1}, PlotStyle -> Darker[Blue], Mesh -> None ]


4

A few additional alternatives: ParametricPlot3D[{v x Sin[x], v x Cos[x], -2 x /3}, {x, 0, (11/4)*Pi}, {v, 1, 1.15}, PlotStyle -> Darker[Blue], Mesh -> None, PlotPoints -> 100] ParametricPlot3D[{v x Sin[x], v x Cos[x], -2 x /3}, {x, 0, (11/4)*Pi}, {v, 0, 1.15}, PlotStyle -> None, PlotPoints -> 100, MeshFunctions -> {#5 &},...


4

If you have version 12.+, you can also use Around to process data1 and use ListLinePlot with the options IntervalMarkers and IntervalMarkersStyle: data1b = Around[#, {#3, #2} - #] & @@@ data1; ListLinePlot[data1b, IntervalMarkers -> "Bands", IntervalMarkersStyle -> Pink, PlotRangePadding -> {Automatic, {Automatic, Scaled[.1]}}]


4

threshold = 1.; Plot[{x^2, x^2/6, ConditionalExpression[0, x <= threshold]}, {x, 0, 2}, PlotStyle -> {Automatic, Orange, None}, Filling -> {2 -> {{3}, {None, LightOrange}}}, PlotRange -> {0, 1}] and Plot[{x^2, x^2/6, Boole[x > threshold ]}, {x, 0, 2}, Exclusions -> {{threshold }}, PlotStyle -> {Automatic, Orange, None}, ...


4

An alternative approach using a single ParametricPlot3D: ClearAll[f1, f2, f3, f4, f5] f1[x_, y_] := {x Sin[x], x Cos[x], -(x/3)} f2[x_, y_] := {Sqrt[y] x Sin[x], y^2 x Cos[x], -(x/3)} f3[x_, y_] := {Sqrt[y] x Sin[x], y^2 x Cos[x], -((x*y^2)/3)} f4[r_: {1, 1.15}][x_, y_] := Module[{t = Rescale[y, r]}, t f2[x, r[[2]]] + (1 - t) f3[x, r[[2]]]] f5[r_: {...


4

The issue caused by differing vertical positions of Axis across plots with filling. plotswithfilling = Table[ Plot[PDF[NormalDistribution[i, 1], x] Exp[-Sqrt[i]/4] /. i -> Range[1, 3, 2] // Evaluate, {x, k, k + 1}, PlotRange -> Full, Filling -> Axis, Axes -> None, PlotStyle -> {ColorData[10][4 + k], Darker[ColorData[...


4

I think what you want is: Plot[Evaluate[{x^2, x}], {x, 1, 2}, PlotRange -> All, Filling -> {1 -> {2}}, PlotStyle->{Blue, Blue} ]


4

Prolog is useful here. Plot[Sin[x], {x, 0, 2 π}, Prolog -> {LightBlue, Rectangle[{3 π/4, -2}, {5 π/4, 2}]}]


3

Try adding Exclusions -> None as an option to the Plot command. Mathematica probably detects the discontinuity in the derivative at 0 and plots in two pieces for negative and positive values. The two pieces may not line up perfectly due to rounding to integer pixel values during rendering: there may be either a gap or an overlap. Turning off exclusion ...


3

Plot[x^3, {x, -1, 1}, Filling -> {1 -> 0}, PlotStyle -> None, FillingStyle -> LightBlue]


3

Here's a tasty one-liner solution for the computational part of the problem! Simplify@Integrate[1, {x, y} \[Element] RegionIntersection[Disk[], Disk[{1, 0}, a]], GenerateConditions -> True]


3

You can use RegionPlot and the options MeshFunctions + Mesh + MeshStyle RegionPlot[Rectangle[], Mesh -> 50, MeshFunctions -> {#1 + #2 &, #1 - #2 &}, MeshStyle -> {Directive[Thin, Blue], Directive[Thin, Red]}, PlotStyle -> None, BoundaryStyle -> None, Frame -> False] Add the option MeshShading -> {{White, Cyan}, {Orange, ...


2

You can use Charting`get2DPlotRange[thePlot to get the plot range taking into account plot range paddings and use it to specify the rectangle coordinates: gr = Graphics[{Opacity[.1], Blue, Rectangle @@ Transpose[{Charting`get2DPlotRange[thePlot][[1]], {100, 140}}]}]; Show[thePlot, gr]


2

Scaled[] along with AbsoluteTime[] is usable in Rectangle[], which allows us to produce the following plot: DateListPlot[data, GridLines -> {None, {60, 85, 100, 140}}, GridLinesStyle -> Directive[Gray, Thin], Joined -> True, PlotRange -> {Automatic, {80, 180}}, Prolog -> {Opacity[0.2, Blue], ...


2

You may use Epilog with DateObject locations on the date-axis in DateListPlot. Therefore you can get the DateBounds on the date-axis, expand this date range to cover the padded plot range, plot the Rectangle. The expanded date rage by 1 day on both ends can be obtained with DatePlus and Inner by Inner[DatePlus, DateObject /@ DateBounds@data[[All, 1]...


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