I want to confine the codomain of my plot. For example, I want to draw y=f(x) only when 3x<y<7x+3. If not, want to draw y=0.
Is it possible in Mathematica plot?
May be
Clear["Global`*"]
f[x_?NumericQ] := x + x^2; (*made one up, since none was given *)
g[x_?NumericQ] := Piecewise[{{f[x], 3 x < f[x] < 7 x + 3}, {0, True}}];
Plot[g[x], {x, 0, 8}, PlotRange -> All]
This is f[x]
Plot[f[x], {x, 0, 8}]
x
is numerical, due to the comparison being made.
$\endgroup$
ConditionalExpression[f[x], 3 x < f[x] < 7 x + 3]
to avoid the extension by zero that one gets with Piecewise
.
$\endgroup$
Commented
Jul 5, 2020 at 11:50
PlotRange -> {{<domain>}, {<codomain>}}
is the way to set the codomain in its normal meaning.
But the OP has in mind restricting the region that is plotted, and that task can be handled with RegionFunction
.
Plot[10 (x - 10) Sin[x], {x, -2, 80},
RegionFunction -> Function[{x, y}, 3 x < y < 7 x + 3]]
Piecewise
. $\endgroup$