3
$\begingroup$

I want to edit this code from the wolfram Documentation Center so that, the red curve comes as dashed lines and the black comes in solid. How to do that using ColorFunction?

Colour a curve red when its absolute coordinate is above 0:

Plot[ Sinc[x], {x, 0, 10}, ColorFunction -> Function[{x, y}, If[y > 0, Red, Black]], ColorFunctionScaling -> False, PlotStyle -> Thick] 

enter image description here

$\endgroup$
2

2 Answers 2

10
$\begingroup$
Plot[Sinc[x], {x, 0, 10}, MeshFunctions -> {Function[{x, y}, y]}, Mesh -> {{0}}, MeshShading -> {Automatic, Directive[Dashed, Red]}, PlotStyle -> Thick] 

enter image description here

$\endgroup$
2
  • $\begingroup$ Isn't there any way to add colours? I tried this, but didn't get the desired result, Plot[Sinc[x], {x, 0, 10}, MeshFunctions -> {Function[{x, y}, y]}, Mesh -> {{0}}, MeshShading -> {Red, Dashed}, PlotStyle -> Thick] $\endgroup$ Commented Mar 18, 2022 at 4:58
  • $\begingroup$ @user84456 Directive[Dashed, Red] $\endgroup$ Commented Mar 18, 2022 at 5:06
4
$\begingroup$
Clear["Global`*"] SolveValues[{Sinc[x] == 0, 0 <= x <= 10}, x] (* {π, 2 π, 3 π} *) Plot[Evaluate[ ConditionalExpression[Sinc[x], #] & /@ {x < Pi || 2 Pi < x < 3 Pi, Pi < x < 2 Pi || x > 3 Pi}], {x, 0, 10}, PlotStyle -> {{Red, Dashed, Thick}, {Black, Thick}}] 

enter image description here

$\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.