Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 016a4e3

Browse files
committed
Merge pull request #2162 from WeatherGod/mplot3d/empty_patch3dcollection
[SPRINT] Closes #1752. Patch3DCollection can now be empty.
2 parents 9c03be0 + 6cd6414 commit 016a4e3

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,23 @@ class Patch3DCollection(PatchCollection):
293293
'''
294294

295295
def __init__(self, *args, **kwargs):
296+
"""
297+
Create a collection of flat 3D patches with its normal vector
298+
pointed in *zdir* direction, and located at *zs* on the *zdir*
299+
axis. 'zs' can be a scalar or an array-like of the same length as
300+
the number of patches in the collection.
301+
302+
Constructor arguments are the same as for
303+
:class:`~matplotlib.collections.PatchCollection`. In addition,
304+
keywords *zs=0* and *zdir='z'* are available.
305+
306+
"""
307+
zs = kwargs.pop('zs', 0)
308+
zdir = kwargs.pop('zdir', 'z')
296309
PatchCollection.__init__(self, *args, **kwargs)
297310
self._old_draw = lambda x: PatchCollection.draw(self, x)
311+
self.set_3d_properties(zs, zdir)
312+
298313

299314
def set_sort_zpos(self,val):
300315
'''Set the position to use for z-sorting.'''
@@ -306,11 +321,11 @@ def set_3d_properties(self, zs, zdir):
306321
self.update_scalarmappable()
307322
offsets = self.get_offsets()
308323
if len(offsets) > 0:
309-
xs, ys = zip(*self.get_offsets())
324+
xs, ys = zip(*offsets)
310325
else:
311-
xs = [0] * len(zs)
312-
ys = [0] * len(zs)
313-
self._offsets3d = juggle_axes(xs, ys, zs, zdir)
326+
xs = []
327+
ys = []
328+
self._offsets3d = juggle_axes(xs, ys, np.atleast_1d(zs), zdir)
314329
self._facecolor3d = self.get_facecolor()
315330
self._edgecolor3d = self.get_edgecolor()
316331

0 commit comments

Comments
 (0)