7
$\begingroup$

I was trying to run a code that I saw on a answer for this question

The code is simply

ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2 Pi}] /.
  Line[l_List] :> {{Red, Polygon[l]}, {Black, Line[l]}}

And the result was supposed to be:

filled circle

However, when I run the same code in Mathematica 10.2 I get this result: filled circle bug

I'm running exactly the same code, no extra global variables. Also, the color Red works perfectly fine in other situations. I've tried RGBColor[1,0,0] and the result is the same.

Similar issues happen with other colors too. Every color is "brighter".

$\endgroup$
7
$\begingroup$

The answer is simple. Per default Mathematica reduces the opacity of the colors. Try the following:

ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2 Pi}] /. 
 Line[l_List] :> {{Red, Polygon[l]}, {Black, Line[l]}}

% /. _Opacity :> Opacity[1]

If you look at the InputForm of your graphics, you will notice a

FaceForm[Opacity[0.3]]

call right in the front. With this knowledge, you can simply fix it by calling:

ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2 Pi}, 
  PlotStyle -> Opacity[1]] /. 
 Line[l_List] :> {{Red, Polygon[l]}, {Black, Line[l]}}
$\endgroup$
6
$\begingroup$

I think using the 2nd argument of Opacity is a slightly simpler way to correct the problem than the methods given by halirutan, although those are perfectly fine.

ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2 Pi}] /. 
  Line[l_List] :> {{Opacity[1, Red], Polygon[l]}, {Black, Line[l]}}

plot

$\endgroup$
  • $\begingroup$ Explicitly setting the alpha channel is even simpler: ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2 Pi}] /. Line[l_List] :> {{RGBColor[1, 0, 0, 1], Polygon[l]}, {Black, Line[l]}}. $\endgroup$ – J. M. will be back soon May 11 '17 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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