Skip to content

Commit d2f58cb

Browse files
committed
Merge pull request #2787 from tacaswell/empty_event_loop
Empty eventplot.
2 parents 6a7a405 + 052542d commit d2f58cb

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

lib/matplotlib/axes.py

+18-12
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

lib/matplotlib/tests/test_axes.py

+9
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,14 @@ def test_eventplot():
12971297
num_collections = len(colls)
12981298
np.testing.assert_equal(num_collections, num_datasets)
12991299

1300+
1301+
@cleanup
1302+
def test_empty_eventplot():
1303+
fig, ax = plt.subplots(1, 1)
1304+
ax.eventplot([[]], colors=[(0.0, 0.0, 0.0, 0.0)])
1305+
plt.draw()
1306+
1307+
13001308
@image_comparison(baseline_images=['vertex_markers'], extensions=['png'],
13011309
remove_text=True)
13021310
def test_vertex_markers():
@@ -1389,6 +1397,7 @@ def test_mixed_collection():
13891397
ax.set_xlim(0, 16)
13901398
ax.set_ylim(0, 16)
13911399

1400+
13921401
@cleanup
13931402
def test_subplot_key_hash():
13941403
ax = plt.subplot(np.float64(5.5), np.int64(1), np.float64(1.2))

0 commit comments

Comments
 (0)