0

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

enter image description here

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
user45951
  • 27
  • 3

1 Answers1

3

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}]

plot

m_goldberg
  • 107,779
  • 16
  • 103
  • 257