2
$\begingroup$

I'm trying to apply a ColorFunction[] to a piecewise plot. For some reason, applying the ColorFunction[] to a plot results in aliasing artifacts (as seen in the image). Is there anyway to get rid of this? (Mathematica 11.0)

cf[x_] := If[x <= 0, Black, Blue];
Rasterize[
 Column[{
   Plot[Piecewise[{{x^2, x >= 0}, {0, x < 0}}], {x, -2, 2}, 
    ColorFunction -> cf, ImageSize -> Large],
   Plot[Piecewise[{{x^2, x >= 0}, {0, x < 0}}], {x, -2, 2}, 
    PlotStyle -> Blue, ImageSize -> Large]
   }], ImageSize -> Large]

Color Function Aliasing

$\endgroup$
2

1 Answer 1

3
$\begingroup$

You can use MeshShading instead of ColorFunction

Rasterize[
 Column[{Plot[Piecewise[{{x^2, x >= 0}, {0, x < 0}}], {x, -2, 2}, 
    Mesh -> {{0}}, MeshShading -> {Black, Blue}, ImageSize -> Large], 
   Plot[Piecewise[{{x^2, x >= 0}, {0, x < 0}}], {x, -2, 2}, 
    PlotStyle -> Blue, ImageSize -> Large]}], ImageSize -> Large]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.