Skip to content

Commit afa8d28

Browse files
authored
Merge pull request matplotlib#17000 from anntzer/eventplotorientation
More stringent eventplot orientations.
2 parents 17ef13b + c498f11 commit afa8d28

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,10 @@ parent figure, though they can be later removed with ``ax.remove()``.
415415

416416
``.BboxBase.inverse_transformed`` is deprecated (call `.BboxBase.transformed`
417417
on the `~.Transform.inverted()` transform instead).
418+
419+
*orientation* of ``eventplot()`` and `.EventCollection`
420+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
421+
Setting the *orientation* of an ``eventplot()`` or `.EventCollection` to "none"
422+
or None is deprecated; set it to "horizontal" instead. Moreover, the two
423+
orientations ("horizontal" and "vertical") will become case-sensitive in the
424+
future.

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12641264
row corresponds to a row or a column of lines (depending on the
12651265
*orientation* parameter).
12661266
1267-
orientation : {'horizontal', 'vertical'}, optional
1267+
orientation : {'horizontal', 'vertical'}, default: 'horizontal'
12681268
The direction of the event collections:
12691269
12701270
- 'horizontal': the lines are arranged horizontally in rows,

lib/matplotlib/collections.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,8 @@ class EventCollection(LineCollection):
14551455
_edge_default = True
14561456

14571457
def __init__(self,
1458-
positions, # Cannot be None.
1459-
orientation=None,
1458+
positions, # Cannot be None.
1459+
orientation='horizontal',
14601460
lineoffset=0,
14611461
linelength=1,
14621462
linewidth=None,
@@ -1471,10 +1471,9 @@ def __init__(self,
14711471
positions : 1D array-like
14721472
Each value is an event.
14731473
1474-
orientation : {None, 'horizontal', 'vertical'}, optional
1474+
orientation : {'horizontal', 'vertical'}, default: 'horizontal'
14751475
The orientation of the **collection** (the event bars are along
1476-
the orthogonal direction). Defaults to 'horizontal' if not
1477-
specified or None.
1476+
the orthogonal direction).
14781477
14791478
lineoffset : scalar, default: 0
14801479
The offset of the center of the markers from the origin, in the
@@ -1584,17 +1583,26 @@ def set_orientation(self, orientation=None):
15841583
15851584
Parameters
15861585
----------
1587-
orientation: {'horizontal', 'vertical'} or None
1588-
Defaults to 'horizontal' if not specified or None.
1589-
"""
1590-
if (orientation is None or orientation.lower() == 'none' or
1591-
orientation.lower() == 'horizontal'):
1592-
is_horizontal = True
1593-
elif orientation.lower() == 'vertical':
1594-
is_horizontal = False
1595-
else:
1596-
cbook._check_in_list(['horizontal', 'vertical'],
1597-
orientation=orientation)
1586+
orientation : {'horizontal', 'vertical'}
1587+
"""
1588+
try:
1589+
is_horizontal = cbook._check_getitem(
1590+
{"horizontal": True, "vertical": False},
1591+
orientation=orientation)
1592+
except ValueError:
1593+
if (orientation is None or orientation.lower() == "none"
1594+
or orientation.lower() == "horizontal"):
1595+
is_horizontal = True
1596+
elif orientation.lower() == "vertical":
1597+
is_horizontal = False
1598+
else:
1599+
raise
1600+
normalized = "horizontal" if is_horizontal else "vertical"
1601+
cbook.warn_deprecated(
1602+
"3.3", message="Support for setting the orientation of "
1603+
f"EventCollection to {orientation!r} is deprecated since "
1604+
f"%(since)s and will be removed %(removal)s; please set it to "
1605+
f"{normalized!r} instead.")
15981606
if is_horizontal == self.is_horizontal():
15991607
return
16001608
self.switch_orientation()

lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,14 +3848,16 @@ def test_empty_eventplot():
38483848
plt.draw()
38493849

38503850

3851-
@pytest.mark.parametrize('data, orientation', product(
3852-
([[]], [[], [0, 1]], [[0, 1], []]),
3853-
('_empty', 'vertical', 'horizontal', None, 'none')))
3851+
@pytest.mark.parametrize('data', [[[]], [[], [0, 1]], [[0, 1], []]])
3852+
@pytest.mark.parametrize(
3853+
'orientation', ['_empty', 'vertical', 'horizontal', None, 'none'])
38543854
def test_eventplot_orientation(data, orientation):
38553855
"""Introduced when fixing issue #6412."""
38563856
opts = {} if orientation == "_empty" else {'orientation': orientation}
38573857
fig, ax = plt.subplots(1, 1)
3858-
ax.eventplot(data, **opts)
3858+
with (pytest.warns(MatplotlibDeprecationWarning)
3859+
if orientation in [None, 'none'] else nullcontext()):
3860+
ax.eventplot(data, **opts)
38593861
plt.draw()
38603862

38613863

0 commit comments

Comments
 (0)