# Opacity and overlapping points on ListPlot3D

I am plotting a dataset on ListPointPlot3D, and in order to give an idea of density of points I used opacity of 0.5. The problem is that that while the opacity of points behind one another is added, when multiple points overlap the opacity is not added; I need a way for the opacity of overlapping points to be added. A minimal example:

ListPointPlot3D[{{1, 1, 1}, {1, 1, 1}, {1, 2, 1}, {1, 2, 2}}, PlotStyle -> Directive[PointSize[0.1], Opacity[0.5]], ViewPoint -> {0, 0, Infinity}]


The first two points overlap completely (thus their opacity does not add), the latter two points overlap in x and y but differ in z (thus their opacity adds). I want to get the opacity of the first two points to add as well.

-
Could you post a minimal example of code that shows the problem? – JasonB Nov 13 '13 at 19:28
@Jason B - here is a minimal example: ListPointPlot3D[{{1, 1, 1}, {1, 1, 1}, {1, 2, 1}, {1, 2, 2}}, PlotStyle -> Directive[PointSize[0.1], Opacity[0.5]], ViewPoint -> {0, 0, Infinity}] The first two points overlap completely (thus their opacity does not add), the latter two points overlap in x and y but differ in z (thus their opacity adds). I want to get the opacity of the first two points to add as well. – Ixxie Nov 13 '13 at 19:59
@YvesKlett - done. – Ixxie Nov 13 '13 at 20:51
How about offsetting duplicate points slightly? – Yves Klett Nov 13 '13 at 21:21
Perhaps useful mathematica.stackexchange.com/a/9191/193 – Dr. belisarius Nov 14 '13 at 2:04

It seems to work if the points are different by a very small amount. This doesn't fix the problem, but it may be a workable solution for you:

ListPointPlot3D[{{1, 1, 1}, {1, 1, 1}, {1, 2, 1}, {1, 2, 2}} +
RandomReal[{-.001, .001}, {4, 3}],
PlotStyle -> Directive[PointSize[0.1], Opacity[0.5]],
ViewPoint -> {0, 0, Infinity},
PlotRange -> {{-0.01, 2.01}, {0.99, 2.01}, {-0.01, 2.01}}]


edit: Just saw that @YvesKlett had the same idea.

-

This solution specifies explicitly the opacity we expect each point to have, making absolutely sure it's right (I'm currently using 0.25 for opacity, as you can see in the second line of code).

(* Create a list in which each point is in its own set *)
list = List /@ {{1, 1, 1}, {1, 1, 1}, {1, 2, 1}, {1, 2, 2}};

(* Compute relative opacities based on multiplicity *)
opacities = list /. (Tally[list] /. {r_, m_} :> Rule[r, Opacity[0.25 m]]);