1
$\begingroup$

The code is exact replica of the code present on the Wolfram site The Hatchfilling command is failing for me, i want to fill the area under the curve with vertical lines. If any suggestions plz do share. Thankyou.

$\endgroup$

2 Answers 2

2
$\begingroup$

Reply to the comment

filling1 = 
  ParametricPlot[{x, y}, {x, 0, 2 \[Pi]}, {y, 0, Sin[x]}, 
   MeshFunctions -> {1*#1 + 0*#2 &}, Mesh -> 80, MeshStyle -> Red, 
   PlotStyle -> None, PlotPoints -> 100, BoundaryStyle -> None];
filling2 = 
  ParametricPlot[{x, y}, {x, 0, 2 \[Pi]}, {y, 0, Cos[x]}, 
   MeshFunctions -> {1*#1 + 0*#2 &}, Mesh -> 80, MeshStyle -> Blue, 
   PlotStyle -> None, PlotPoints -> 100, BoundaryStyle -> None];
Show[Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}, 
  PlotStyle -> {Red, Blue}], filling1, filling2]

enter image description here

Maybe work in your Mathematica version.

plot = Plot[Sin[x], {x, 0, 2 Pi}];
filling = 
  ParametricPlot[{x, y}, {x, 0, 2 π}, {y, 0, Sin[x]}, 
   MeshFunctions -> {1*#1 + 0*#2 &}, Mesh -> 80, PlotStyle -> None, 
   PlotPoints -> 100, BoundaryStyle -> None];
Show[plot, filling]

enter image description here

$\endgroup$
3
  • $\begingroup$ Worked. Thankyou! $\endgroup$ Jun 12, 2021 at 8:55
  • $\begingroup$ If we want to add another function let's say cos[x], Can this code be transformed for it. Tried but Alas! $\endgroup$ Jun 12, 2021 at 9:16
  • $\begingroup$ @SyedShahmirKazmi See the updated. $\endgroup$
    – cvgmt
    Jun 12, 2021 at 14:43
2
$\begingroup$

It seems HatchFilling is not available in your Mathematica. Which version are you using? This functionality was introduced in version 12.1.

You can get what you want using

Plot[Sin[x], {x, 0, 2 Pi}, Filling -> Axis, 
 FillingStyle -> HatchFilling[Pi/2]]
$\endgroup$
1
  • $\begingroup$ ok understood. Mine version is 11.2 $\endgroup$ Jun 12, 2021 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.