Skip to content

RFC: Allow users to force zorder in 3D plots #14175

Closed
@kentcr

Description

@kentcr

At present, the draw order order in 3D plots is determined exclusively by sorting the values returned by calling do_3d_projection() in each collection/patch:

# Calculate projection of collections and patches and zorder them.
# Make sure they are drawn above the grids.
zorder_offset = max(axis.get_zorder()
for axis in self._get_axis_list()) + 1
for i, col in enumerate(
sorted(self.collections,
key=lambda col: col.do_3d_projection(renderer),
reverse=True)):
col.zorder = zorder_offset + i
for i, patch in enumerate(
sorted(self.patches,
key=lambda patch: patch.do_3d_projection(renderer),
reverse=True)):
patch.zorder = zorder_offset + i

However, this sorting is not always ideal and a common issue reported by users. I'd propose adding a "force_zorder" optional parameter to Axes3D (defaulting to False) that would ignore the above calculation and instead use the zorder already stored in each collection/patch, i.e.

if self.force_zorder:
    for col in self.collections:
        col.zorder = zorder_offset + col.zorder
    for patch in self.patches:
        patch.zorder = zorder_offset + patch.zorder
else:
    # current code

This keeps existing behavior as default, but allows users to override that behavior. This does allow users to specify duplicate or negative zorders, as they can in 2D plots, but that hasn't generated errors in my testing.

However, not being at all familiar with the deeper workings, I'd rather get comments/concerns from the matplotlib maintainers and contributors before setting off to produce a full pull request.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions