@@ -311,9 +311,14 @@ def __init__(self, *args, **kwargs):
311311 :class:`~matplotlib.collections.PatchCollection`. In addition,
312312 keywords *zs=0* and *zdir='z'* are available.
313313
314+ Also, the keyword argument "depthshade" is available to
315+ indicate whether or not to shade the patches in order to
316+ give the appearance of depth (default is *True*).
317+ This is typically desired in scatter plots.
314318 """
315319 zs = kwargs .pop ('zs' , 0 )
316320 zdir = kwargs .pop ('zdir' , 'z' )
321+ self ._depthshade = kwargs .pop ('depthshade' , True )
317322 PatchCollection .__init__ (self , * args , ** kwargs )
318323 self ._old_draw = lambda x : PatchCollection .draw (self , x )
319324 self .set_3d_properties (zs , zdir )
@@ -340,14 +345,16 @@ def set_3d_properties(self, zs, zdir):
340345 def do_3d_projection (self , renderer ):
341346 xs , ys , zs = self ._offsets3d
342347 vxs , vys , vzs , vis = proj3d .proj_transform_clip (xs , ys , zs , renderer .M )
343- #FIXME: mpl allows us no way to unset the collection alpha value
344- #self._alpha = None
345- fcs = mcolors .colorConverter .to_rgba_array (self ._facecolor3d ,
346- self ._alpha )
347- mcs = mcolors .colorConverter .to_rgba_array (self ._edgecolor3d ,
348- self ._alpha )
349- self .set_facecolors (zalpha (fcs , vzs ))
350- self .set_edgecolors (zalpha (mcs , vzs ))
348+
349+ fcs = (zalpha (self ._facecolor3d , vzs ) if self ._depthshade else
350+ self ._facecolor3d )
351+ fcs = mcolors .colorConverter .to_rgba_array (fcs , self ._alpha )
352+ self .set_facecolors (fcs )
353+
354+ ecs = (zalpha (self ._edgecolor3d , vzs ) if self ._depthshade else
355+ self ._edgecolor3d )
356+ ecs = mcolors .colorConverter .to_rgba_array (ecs , self ._alpha )
357+ self .set_edgecolors (ecs )
351358 super (self .__class__ , self ).set_offsets (list (zip (vxs , vys )))
352359
353360 if vzs .size > 0 :
@@ -367,9 +374,22 @@ class Path3DCollection(Collection3D, PathCollection):
367374 pass
368375
369376
370- def patch_collection_2d_to_3d (col , zs = 0 , zdir = 'z' ):
371- """Convert a PatchCollection to a Patch3DCollection object."""
377+ def patch_collection_2d_to_3d (col , zs = 0 , zdir = 'z' , depthshade = True ):
378+ """
379+ Convert a :class:`~matplotlib.collections.PatchCollection` into a
380+ :class:`Patch3DCollection` object
381+ (or a :class:`~matplotlib.collections.PathCollection` into a
382+ :class:`Path3DCollection` object).
383+
384+ Keywords:
385+ *za* The location or locations to place the patches in the
386+ collection along the *zdir* axis. Defaults to 0.
387+ *zdir* The axis in which to place the patches. Default is "z".
388+ *depthshade* Whether to shade the patches to give a sense of depth.
389+ Defaults to *True*.
390+
372391
392+ """
373393 # The tricky part here is that there are several classes that are
374394 # derived from PatchCollection. We need to use the right draw method.
375395 col ._old_draw = col .draw
@@ -378,6 +398,7 @@ def patch_collection_2d_to_3d(col, zs=0, zdir='z'):
378398 col .__class__ = Path3DCollection
379399 elif isinstance (col , PatchCollection ):
380400 col .__class__ = Patch3DCollection
401+ col ._depthshade = depthshade
381402 col .set_3d_properties (zs , zdir )
382403
383404class Poly3DCollection (PolyCollection ):
0 commit comments