Skip to content

Axes3D/add_collection3D( LineCollection ): Z-Index forces incorrect drawing order #3884

Open
@demisjohn

Description

@demisjohn

Hello,
I believe I have found a bug in using add_collection3d() to produce plots like in this example:
'Matplotlib Tutorial / Polygon plots / Axes3D.add_collection3d' -- sorry, you have to click "Polygon Plots" due to the page's inability to target properly
(The actual demo script is here. )
The bug is exhibited when you use a LineCollection instead of PolyCollection (the example uses PolyCollection)

My guess is that, for a 3DLineCollection, the Z-Index controls the drawing order, such that the highest valued Z-Index is always obscured by the lower-valued Z-indices, even when you rotate the plot (azimuth angle).

I have modified the aforementioned PolyCollection example (which is bugless) to plot the same data via a LineCollection instead, which immediately reproduces the plotting issue.

Here is the example of a Collection3D of a LineCollection (note the viewing Azimuth angle), rotated to look as expected, with the appropriate Lines obscuring those behind them:
screen shot 2014-12-03 at 9 19 15 pm

However, with the plot rotated 90 degrees (Azimuthal angle), we get an Incorrect drawing (the Yellow curves should be at the Back):
screen shot 2014-12-03 at 9 19 20 pm

To reiterate, this problem does Not occur with a PolyCollection passed to add_collection3d(), but does when passing a LineCollection.

Please let me know if you're able to reproduce the problem, and thanks for your time & patience with a first-time poster.

Here is the aforementioned example script, modified to plot a LineCollection instead (and alpha set to 1.0 to aid visual clarity).


from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections import LineCollection   # was `PolyCollection`
from matplotlib.colors import colorConverter
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')

alpha_=1.0  # to accentuate the issue

cc = lambda arg: colorConverter.to_rgba(arg, alpha=alpha_)

xs = np.arange(0, 10, 0.4)
verts = []
zs = [0.0, 1.0, 2.0, 3.0]
for z in zs:
    ys = np.random.rand(len(xs))
    ys[0], ys[-1] = 0, 0
    verts.append(list(zip(xs, ys)))

poly = LineCollection(verts, facecolor = [cc('r'), cc('g'), cc('b'),
                                           cc('y')])   # was `PolyCollection`, and `facecolor` was `facecolors`
poly.set_alpha(alpha_)
ax.add_collection3d(poly, zs=zs, zdir='y')

ax.set_xlabel('X')
ax.set_xlim3d(0, 10)
ax.set_ylabel('Y')
ax.set_ylim3d(-1, 4)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 1)

plt.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github Actiontopic: mplot3d

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions