Description
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:
matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
Lines 294 to 307 in 40583b0
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!