Skip to content

Commit f62a947

Browse files
committed
Added support for empty input to scatter3d and plot3d.
1 parent b516ae0 commit f62a947

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,10 @@ def do_3d_projection(self, renderer):
319319
self.set_edgecolors(zalpha(self._edgecolor3d, vzs))
320320
PatchCollection.set_offsets(self, zip(vxs, vys))
321321

322-
return min(vzs)
322+
if vzs.size > 0 :
323+
return min(vzs)
324+
else :
325+
return np.nan
323326

324327
def draw(self, renderer):
325328
self._old_draw(renderer)
@@ -461,8 +464,10 @@ def do_3d_projection(self, renderer):
461464
zvec = np.array([[0], [0], [self._sort_zpos], [1]])
462465
ztrans = proj3d.proj_transform_vec(zvec, renderer.M)
463466
return ztrans[2][0]
464-
else:
465-
return np.min(tzs)
467+
elif tzs.size > 0 :
468+
return self._zsortfunc(tzs)
469+
else :
470+
return np.nan
466471

467472
def set_facecolor(self, colors):
468473
PolyCollection.set_facecolor(self, colors)
@@ -559,8 +564,9 @@ def get_colors(c, num):
559564
def zalpha(colors, zs):
560565
"""Modify the alphas of the color list according to depth"""
561566
colors = get_colors(colors, len(zs))
562-
norm = Normalize(min(zs), max(zs))
563-
sats = 1 - norm(zs) * 0.7
564-
colors = [(c[0], c[1], c[2], c[3] * s) for c, s in zip(colors, sats)]
567+
if zs.size > 0 :
568+
norm = Normalize(min(zs), max(zs))
569+
sats = 1 - norm(zs) * 0.7
570+
colors = [(c[0], c[1], c[2], c[3] * s) for c, s in zip(colors, sats)]
565571
return colors
566572

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,17 +670,29 @@ def plot(self, xs, ys, *args, **kwargs):
670670
Other arguments are passed on to
671671
:func:`~matplotlib.axes.Axes.plot`
672672
'''
673-
673+
# FIXME: This argument parsing might be better handled
674+
# when we set later versions of python for
675+
# minimum requirements. Currently at 2.4.
676+
# Note that some of the reason for the current difficulty
677+
# is caused by the fact that we want to insert a new
678+
# (semi-optional) positional argument 'Z' right before
679+
# many other traditional positional arguments occur
680+
# such as the color, linestyle and/or marker.
674681
had_data = self.has_data()
675682
zs = kwargs.pop('zs', 0)
676683
zdir = kwargs.pop('zdir', 'z')
677684

678685
argsi = 0
679686
# First argument is array of zs
680687
if len(args) > 0 and cbook.iterable(args[0]) and \
681-
len(xs) == len(args[0]) and cbook.is_scalar(args[0][0]):
682-
zs = args[argsi]
683-
argsi += 1
688+
len(xs) == len(args[0]) :
689+
# So, we know that it is an array with
690+
# first dimension the same as xs.
691+
# Next, check to see if the data contained
692+
# therein (if any) is scalar (and not another array).
693+
if len(args[0]) == 0 or cbook.is_scalar(args[0][0]) :
694+
zs = args[argsi]
695+
argsi += 1
684696

685697
# First argument is z value
686698
elif len(args) > 0 and cbook.is_scalar(args[0]):

0 commit comments

Comments
 (0)