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$
0

2 Answers 2

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

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.