How can I plot a curve with a filled sub-domain as shown below?

enter image description here

  • 1
    $\begingroup$ Make two Plots with a different V range, use Filling in one, combine them with Show. What have you tried so far? Did you look at the Plot documentation? $\endgroup$ – Szabolcs Sep 9 '17 at 14:24
  • $\begingroup$ closely related Q/A: Filling between boundaries $\endgroup$ – kglr Sep 9 '17 at 17:58

Let f be the function to plot. Define a 2nd function, g that restricts f to the given sub-domain. Use the fill option Filling -> 2 -> Axis.

f[x_] := 1/x^2
g[x_] := Piecewise[{{f[x], 3/2 <= x <= 2}}, Null]

Plot[{f[x], g[x]}, {x, 1, 4},
  Filling -> 2 -> Axis,
  PlotRange -> {0, Automatic}]


  • $\begingroup$ Thanks very much $\endgroup$ – user45951 Sep 10 '17 at 1:20
  • $\begingroup$ @user45951. I'm glad you find my answer useful. Please consider accepting it. You can do that by clicking on the check mark that appears on the left of the answer below the down arrow. $\endgroup$ – m_goldberg Sep 10 '17 at 1:27

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