Let's consider a simple example. I want to plot a function on [0;2]
, depending on a condition: if x<1
, I want to plot x^2
, otherwise x^2-1
. I found out how to do it:
Plot[If[x < 1, x^2, x^2 - 1], {x, 0, 2}]
But in my problem I need to plot the same function (x^2
), with 1 color for x<1
and with another color otherwise (say, blue and red). I didn't find how to it. It seems like I cannot include colormap function inside the if
condition.
Thanks
PlotStyle
), everything works. Once I combine them withShow
function, it plots everything with the second color, ignoring the first $\endgroup$Show
never changes the colour. Are you usingShow[Plot[..., PlotStyle -> Red], Plot[..., PlotStyle -> Blue], PlotRange -> All]
? I forgot to say that you might needPlotRange -> All
withinShow
. $\endgroup$If
expression toPiecewise
withPiecewiseExpand
, and then this question is a direct duplicate of the one now linked above your post. See also: (6826), (8199) $\endgroup$