0

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574

2 Answers2

4
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

kglr
  • 394,356
  • 18
  • 477
  • 896
1
Plot[Sin[x], {x, 0, 10}, PlotStyle -> Thick, 
 ColorFunction -> Function[{x, y}, If[y > .5, Blue, Green]], 
 ColorFunctionScaling -> False]
jiaoeyushushu
  • 911
  • 6
  • 10