0
$\begingroup$

I'm very new to Mathematica. I would like to plot a function $f(x,p)=y$, where $p$ is a parameter from 0 to 1. I would like the plot to be, for instance, green, for $y>a$, where $a$ is some number I define, and red for $y \le a$. How can I achieve this? thanks in advance.

$\endgroup$
4
$\begingroup$
ClearAll[f]
f[x_, p_] := x p Sin[p x]
a = 4;

Plot[f[x, 3], {x, 0, 2 π}, MeshFunctions -> {#2 &}, Mesh -> {{a}},
  PlotStyle -> Thick, MeshStyle -> None, MeshShading -> {Red, Green}]

enter image description here

| improve this answer | |
$\endgroup$
1
$\begingroup$
Plot[Sin[x], {x, 0, 10}, PlotStyle -> Thick, 
 ColorFunction -> Function[{x, y}, If[y > .5, Blue, Green]], 
 ColorFunctionScaling -> False]
| improve this answer | |
$\endgroup$

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