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

Skip to content

Commit d82d756

Browse files
authored
Merge pull request #10578 from afvincent/fix_eventplot_is_horizontal
Fix eventplot exception due to uninitiliazed `_is_horizontal` attribute
2 parents 9b48fd8 + f849d79 commit d82d756

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,10 +1271,11 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12711271
minline = (lineoffsets - linelengths).min()
12721272
maxline = (lineoffsets + linelengths).max()
12731273

1274-
if colls[0].is_horizontal():
1275-
corners = (minpos, minline), (maxpos, maxline)
1276-
else:
1274+
if (orientation is not None and
1275+
orientation.lower() == "vertical"):
12771276
corners = (minline, minpos), (maxline, maxpos)
1277+
else: # "horizontal", None or "none" (see EventCollection)
1278+
corners = (minpos, minline), (maxpos, maxline)
12781279
self.update_datalim(corners)
12791280
self.autoscale_view()
12801281

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,6 +3236,17 @@ def test_empty_eventplot():
32363236
plt.draw()
32373237

32383238

3239+
@pytest.mark.parametrize('data, orientation', product(
3240+
([[]], [[], [0, 1]], [[0, 1], []]),
3241+
('_empty', 'vertical', 'horizontal', None, 'none')))
3242+
def test_eventplot_orientation(data, orientation):
3243+
"""Introduced when fixing issue #6412. """
3244+
opts = {} if orientation == "_empty" else {'orientation': orientation}
3245+
fig, ax = plt.subplots(1, 1)
3246+
ax.eventplot(data, **opts)
3247+
plt.draw()
3248+
3249+
32393250
@image_comparison(baseline_images=['marker_styles'], extensions=['png'],
32403251
remove_text=True)
32413252
def test_marker_styles():

0 commit comments

Comments
 (0)