18
$\begingroup$

I am trying to render a matrix as a depth map:

data = {{1, 1, 1, 1}, {1, 0, 3, 1}, {2, 0, 0, 1}};
ListPlot3D[data, Mesh -> None, InterpolationOrder -> 0, 
           Filling -> Bottom, FillingStyle -> {Opacity[1]}, 
           ColorFunction -> "SolarColors", ViewPoint -> {Pi, Pi, 5}]

my depth map

However, for the matrix element with the lowest value, the height of the corresponding bar in the plot is zero. This results in rendering artifacts (z-fighting).

Viewing the graph from below or rotating the graph makes the problem more obvious:

see the artifacts

$\endgroup$
5
  • $\begingroup$ I get a different issue, from some viewpoints I get this, but from others I get this $\endgroup$
    – Jason B.
    Commented May 24, 2016 at 8:29
  • $\begingroup$ Does FillingStyle -> {Opacity[.9]} help you any? $\endgroup$
    – Yves Klett
    Commented May 24, 2016 at 8:33
  • $\begingroup$ @JasonB In my understanding of the problem, the "lid" and "bottom" plane of the bar are positioned identicaly, resulting in them "fighting" to be displayed. The result changes depending on your view angle. I choose a specifically bad angle as an example. I will add an animation showing how it flickers depending on the angle. $\endgroup$
    – R D
    Commented May 24, 2016 at 8:36
  • $\begingroup$ @YvesKlett No. Same problem. Thanks for the suggestion. $\endgroup$
    – R D
    Commented May 24, 2016 at 8:37
  • 1
    $\begingroup$ A duplicate of this. Since it is partly a graphics-card-related issue, that Q was closed as too localized. I do not agree with this, because it is also partly an overlapping-planes-related issue that is easily resolvable by code and no need to buy a bigger machine. Nonetheless, your example looks ok at my screen. $\endgroup$ Commented Jul 14, 2016 at 7:30

3 Answers 3

6
$\begingroup$

This is not entirely the same, as it changes coloring and z-scaling, but perhaps something similar may be of help. Essentially, the zero values are lifted by a small increment, while the original z-range is preserved.

data = {{1, 1, 1, 1}, {1, 0, 3, 1}, {2, 0, 0, 1}};
ListPlot3D[data /. x_ /; x < .01 -> 0.01, Mesh -> None, 
 InterpolationOrder -> 0, Filling -> Bottom, 
 FillingStyle -> {Opacity[1]}, ColorFunction -> "SolarColors", 
 ViewPoint -> {Pi, Pi, 5}, 
 PlotRange -> {Automatic, Automatic, {Min[data], Max[data]}}]

EDIT

even better (shorter and broader applicability) as proposed by the OP:

ListPlot3D[data, Mesh -> None, InterpolationOrder -> 0, 
 Filling -> Bottom, FillingStyle -> {Opacity[1]}, 
 ColorFunction -> "SolarColors", ViewPoint -> {Pi, Pi, 5}, 
 PlotRange -> {Automatic, Automatic, {Min[data] - 0.01, Max[data]}}]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Could you change your solution to ListPlot3D[data + 0.01, ... PlotRange -> {Automatic, Automatic, {Min[data], Max[data] + 0.01}}] or something similar? Otherwise it will not work for datasets with Min[data] != 0 or all zero values. $\endgroup$
    – R D
    Commented May 24, 2016 at 9:36
  • 1
    $\begingroup$ Event better: ListPlot3D[data, ... PlotRange -> {Automatic, Automatic, {Min[data] - 0.01, Max[data]}}] $\endgroup$
    – R D
    Commented May 24, 2016 at 9:54
  • $\begingroup$ Good suggestion! I added that unless you want to self-answer... (which you can still do anyway). $\endgroup$
    – Yves Klett
    Commented May 24, 2016 at 12:46
14
$\begingroup$

In at least this case, Method -> {"RelieveDPZFighting" -> True}, which is useful when you have nearly coplanar polygons in your plot, removes the observed jitter and streakiness. I picked this up from Brett.

{ListPlot3D[data, ColorFunction -> "SolarColors", Filling -> Bottom, 
            FillingStyle -> {Opacity[1]}, InterpolationOrder -> 0, Mesh -> None,
            PlotLabel -> "Before", ViewPoint -> {-Pi, -Pi, -2}], 
 ListPlot3D[data, ColorFunction -> "SolarColors", Filling -> Bottom, 
            FillingStyle -> {Opacity[1]}, InterpolationOrder -> 0, Mesh -> None,
            Method -> {"RelieveDPZFighting" -> True}, PlotLabel -> "After", 
            ViewPoint -> {-Pi, -Pi, -2}]} // GraphicsRow

a comparison

$\endgroup$
3
  • $\begingroup$ Oooh, this sounds interesting... just firing up my system to test on some old-time problem cases. $\endgroup$
    – Yves Klett
    Commented Jul 11, 2016 at 6:47
  • $\begingroup$ Huh, no help for my coplanar artifacts (those remain belligerent as ever), but still good to knowl😊 $\endgroup$
    – Yves Klett
    Commented Jul 14, 2016 at 15:12
  • 1
    $\begingroup$ Hmm, maybe you should post your stuff in a new question, @Yves. Sounds like a stiff challenge... $\endgroup$ Commented Jul 14, 2016 at 15:17
9
$\begingroup$

In v10.1 under Windows x64 I experience no "z-fighting" in this example when using the "BSPTree" rendering method. This method may be individually selected using BaseStyle

data = {{1, 1, 1, 1}, {1, 0, 3, 1}, {2, 0, 0, 1}};
plot = ListPlot3D[data, Mesh -> None, InterpolationOrder -> 0, Filling -> Bottom, 
  FillingStyle -> {Opacity[1]}, ColorFunction -> "SolarColors", 
  ViewPoint -> {Pi, Pi, 5}]

Show[plot,
 BaseStyle -> 
  RenderingOptions ->
   {"Graphics3DRenderingEngine" -> "BSPTree"}]

The same Option may be given in ListPlot3D but I separated it with Show for clarity.

It may also be set globally for a session with:

SetOptions[$FrontEndSession, 
  RenderingOptions -> {"Graphics3DRenderingEngine" -> "BSPTree"}]

Or persistently by changing $FrontEndSession to $FrontEnd in the code above.


Other cases where the rendering method is important:

And one I just found which basically duplicates this question:

$\endgroup$

Your Answer

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

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