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

Skip to content

Commit 052542d

Browse files
committed
BUG : allows empty event lists to be passed in
fixes matplotlib#2786
1 parent fa9fb7e commit 052542d

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

lib/matplotlib/axes.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3988,18 +3988,24 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
39883988
colls.append(coll)
39893989

39903990
if len(positions) > 0:
3991-
minpos = min(position.min() for position in positions)
3992-
maxpos = max(position.max() for position in positions)
3993-
3994-
minline = (lineoffsets - linelengths).min()
3995-
maxline = (lineoffsets + linelengths).max()
3996-
3997-
if colls[0].is_horizontal():
3998-
corners = (minpos, minline), (maxpos, maxline)
3999-
else:
4000-
corners = (minline, minpos), (maxline, maxpos)
4001-
self.update_datalim(corners)
4002-
self.autoscale_view()
3991+
# try to get min/max
3992+
min_max = [(np.min(_p), np.max(_p)) for _p in positions
3993+
if len(_p) > 0]
3994+
# if we have any non-empty positions, try to autoscale
3995+
if len(min_max) > 0:
3996+
mins, maxes = zip(*min_max)
3997+
minpos = np.min(mins)
3998+
maxpos = np.max(maxes)
3999+
4000+
minline = (lineoffsets - linelengths).min()
4001+
maxline = (lineoffsets + linelengths).max()
4002+
4003+
if colls[0].is_horizontal():
4004+
corners = (minpos, minline), (maxpos, maxline)
4005+
else:
4006+
corners = (minline, minpos), (maxline, maxpos)
4007+
self.update_datalim(corners)
4008+
self.autoscale_view()
40034009

40044010
return colls
40054011

0 commit comments

Comments
 (0)