Highlighting a certain section of a plot

I assumed that the following plot for Sin would be red between .5 and .7, but it's all blue. Am I misunderstanding what Exclusions do? The Help is rather uninformative.

Plot[Sin[x], {x, 0, 2 π}, ExclusionsStyle -> Red,
Exclusions -> {.5 < Sin[x] < .7}]

• 1. Did you only read the description at the beginning of document of Exclusions, etc. or even only check ?Exclusions? It's important to read the examples in the document by pressing F1 when using Mathematica. If you check them, you'll probably notice that, what you need is ColorFunction. (A strongly related example can be found in Options section of Plot document. ) 2. Why do you mention python's eval in the title? Is it another question? Sep 18, 2022 at 3:08
• Exclusions is to exclude singularities and documentation shows only equations, not inequalities, and some strings like "Discontinuities". To exclude part of a graph, you can use the option RegionFunction or ConditionalExpression[Sin[x], Not[.5 < Sin[x] < .7]], but the excluded domain won't be colored. To color part of a graph, you can use MeshFunctions and MeshShading. Can you indicate what you want? Sep 18, 2022 at 3:13
• @MichaelE2 Plot[Sin[x], {x, 0, 2 π}, ColorFunction -> Function[{x, y}, If[.5 < y < .7, Red, Automatic]], ColorFunctionScaling -> False], I guess. Sep 18, 2022 at 3:19
• BTW, python's eval is amount to ToExpression of Mathematica, if I understand the document of eval correctly. Sep 18, 2022 at 5:49

Plot[Sin[x], {x, 0, 2 π}, Mesh -> {{.5, .7}},
MeshFunctions -> Function[{x, y}, y],
MeshShading -> {Automatic, Red, Automatic}, MeshStyle -> Green]


Clear["Global*"]


Exclusions can be defined by equations but not by inequalities

Plot[Sin[x], {x, 0, 2 π},
Exclusions -> {Sin[x] == 0.5, Sin[x] == 0.7},
ExclusionsStyle -> {AbsolutePointSize[6], Red}]


Plot[Sin[x], {x, 0, 2 π},
ColorFunction -> Function[{x, y},
Piecewise[{{Red, 0.5 < y < 0.7}}, Blue]],
ColorFunctionScaling -> False]


Another variation could be to plot a regular curve p1 and superimpose the same curve on top of it constrained with a RegionFunction such as p2 as follows.

p1 = Plot[Sin[x]
, {x, 0, 2 π}
, PlotStyle -> {Thick, Blue}
];

p2 = Plot[Sin[x]
, {x, 0, 2 π}
, PlotRange -> All
, RegionFunction -> Function[{x}, 0.5 < Sin[x] < 0.7]
, PlotStyle -> {Thick, Red}
];

Show[p1, p2]
`