Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I am trying to use a ColorFunction with Opacity in ContourPlot. Here's my code:

data = RandomVariate[BinormalDistribution[.75], 10];
d = SmoothKernelDistribution[data];
cf[z_] := {Opacity[z], Red};
sc1 = ContourPlot[
   Evaluate@PDF[d, {x, y}], {x, -3, 3}, {y, -3, 3}, 
   PlotRange -> All, PlotPoints -> 50, ColorFunction -> cf, 
   ColorFunctionScaling -> True]

And here's what it produces:

enter image description here

How can the ugly mesh be avoided? I am using Mathematica 8.0.1 in OS X.

share|improve this question

marked as duplicate by J. M. Apr 4 '13 at 14:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

does Mesh -> None give what you need? Btw, I don't get the "ugly mesh" with Version 9 on Windows Vista 64 bit. – kglr Feb 28 '13 at 20:34
@Guillochon Here it works fine Mathematica 9.0.1 Win7 64b – Lou Feb 28 '13 at 20:36
Mesh -> None is not a legal option for ContourPlot for me. I am using Mathematica 8.0.1 for OS X. – Guillochon Feb 28 '13 at 20:37
You may use Mesh->False, but it doesn't do what you want – belisarius has settled Feb 28 '13 at 20:41
As above, what platform are you on? Can you please include that information. – Mike Honeychurch Feb 28 '13 at 21:05

3 Answers 3

up vote 7 down vote accepted

If you are using OS X the use undocumented Method -> {"TransparentPolygonMesh" -> True}

enter image description here

share|improve this answer
Well, it doesn't solve the problem here – belisarius has settled Feb 28 '13 at 20:57
How do you mean? Am I misreading the question? I thought he wanted the mesh to go (??) – Mike Honeychurch Feb 28 '13 at 20:59
In my machine the mesh disappears with Style[sc1, Antialiasing -> False] but not with this solution. Probably version/platform dependent – belisarius has settled Feb 28 '13 at 21:01
@belisarius Yes, the problem is Mac-specific. – Szabolcs Feb 28 '13 at 21:02
@Szabolcs I'm on Windows, and I have the same problem. The solution is Mac-specific :) – belisarius has settled Feb 28 '13 at 21:03

Since you are looking at a PDF, I would use SmoothDensityHistogram to plot it, instead.

data = RandomVariate[BinormalDistribution[.75], 10];
d = SmoothKernelDistribution[data];
cf[z_] := {Opacity[z], Red};

sc1 = SmoothDensityHistogram[data , Automatic, "PDF", 
  PlotRange -> All, ColorFunction -> cf, Mesh -> 10, 
  MeshStyle -> Directive[Opacity[0.5], Black]]

enter image description here

By default, in this case, it was not displaying the contours, so I added them via Mesh and MeshStyle. Modify to taste.

share|improve this answer
I looked at this as an option, but the problem was not being able to get flat shading between the contours. – Guillochon Feb 28 '13 at 21:01
@Guillochon, why do you want the flat shading they don't truly represent the function? – s0rce Feb 28 '13 at 21:02
It's a stylistic choice, the smooth coloring is hard to see, and is harder to notice when printed to paper. – Guillochon Feb 28 '13 at 21:15

Just for behavior documentation. Mathematica 8.0 on WinXP.

GraphicsRow[Style[sc1, Antialiasing -> #] & /@ {True, False}]

Mathematica graphics

share|improve this answer
When I tested this on Windows 7, sc1 without any antialiasing option produced an antialiased graphic without a visible mesh. (I.e. when not specifying Antialiasing at all, the problem didn't appear.) – Szabolcs Feb 28 '13 at 21:51
I get the same with mma 9.0.0 win7 64 bit – Ajasja Feb 28 '13 at 21:57
@Szabolcs So it's definitely due to a change in defaults. I think specifying the Antialiasing makes the results portable – belisarius has settled Feb 28 '13 at 21:58
@Ajasja Try including Automatic too in the list of options, not just True and False. This is what I got with Automatic: – Szabolcs Mar 1 '13 at 0:24
I have to comment on this again, because it's misleading: on all Windows systems I tried, there's no problem with the mesh if you don't use any anti-aliasing setting at all. A fair example would show Antialiasing -> Automatic as well. This example prevented the original question from being closed as a duplicate even though it really should be. It's a Mac OS X specific issue which is solved by the suggestion in the accepted answer. – Szabolcs Apr 4 '13 at 14:09

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