2
Plot[{Sin[x], Cos[x]}, {x, 0, 10}, Mesh -> {{0, π}}, MeshShading -> {Black, Red}]

In the above, how can I specify that I want the mesh for just, say the Sin function and not the Cos? I know I can use two plots and combine them with Show, but this is not what I want.

kglr
  • 394,356
  • 18
  • 477
  • 896
Andrei
  • 901
  • 5
  • 17

2 Answers2

1
Plot[{ConditionalExpression[Sin[x], 0 <= x <= Pi], 
      ConditionalExpression[Sin[x], Pi < x <= 10], Cos[x]}, {x, 0, 10}, 
      PlotStyle -> {Red, Black, Black}]

enter image description here

Andrei
  • 901
  • 5
  • 17
0
Plot[{Sin[x], Cos[x]}, {x, 0, 4 Pi}, 
 MeshFunctions -> {Boole[#2 === Sin[#1]] # &},
 Mesh -> {{0, Pi, 2 Pi, 3 Pi, 4 Pi}}, 
 MeshShading -> {Black, Directive[ Red, Thick]},
 PlotPoints -> 900]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896