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

Skip to content

Commit 2ba8144

Browse files
committed
FIX: process list of lists for eventplot
TST: add test for eventplot
1 parent 95463c3 commit 2ba8144

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,10 +1254,11 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12541254
--------
12551255
.. plot:: gallery/lines_bars_and_markers/eventplot_demo.py
12561256
"""
1257-
# We do the conversion first since not all unitized data is uniform
1258-
positions, lineoffsets, linelengths = self._process_unit_info(
1259-
[("x", positions), ("y", lineoffsets), ("y", linelengths)], kwargs)
12601257

1258+
lineoffsets, linelengths = self._process_unit_info(
1259+
[("y", lineoffsets), ("y", linelengths)], kwargs)
1260+
1261+
# fix positions, noting that it can be a list of lists:
12611262
if not np.iterable(positions):
12621263
positions = [positions]
12631264
elif any(np.iterable(position) for position in positions):
@@ -1268,6 +1269,11 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12681269
if len(positions) == 0:
12691270
return []
12701271

1272+
poss = []
1273+
for position in positions:
1274+
poss += self._process_unit_info([("x", position)], kwargs)
1275+
positions = poss
1276+
12711277
# prevent 'singular' keys from **kwargs dict from overriding the effect
12721278
# of 'plural' keyword arguments (e.g. 'color' overriding 'colors')
12731279
colors = cbook._local_over_kwdict(colors, kwargs, 'color')
@@ -4322,9 +4328,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
43224328
43234329
"""
43244330
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
4325-
43264331
x, y = self._process_unit_info([("x", x), ("y", y)], kwargs)
4327-
43284332
# np.ma.ravel yields an ndarray, not a masked array,
43294333
# unless its argument is a masked array.
43304334
x = np.ma.ravel(x)

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,6 +4137,21 @@ def test_eventplot_orientation(data, orientation):
41374137
plt.draw()
41384138

41394139

4140+
@check_figures_equal(extensions=['png'])
4141+
def test_eventplot_units_list(fig_test, fig_ref):
4142+
# test that list of lists converted properly:
4143+
ts_1 = [datetime.datetime(2021, 1, 1), datetime.datetime(2021, 1, 2),
4144+
datetime.datetime(2021, 1, 3)]
4145+
ts_2 = [datetime.datetime(2021, 1, 15), datetime.datetime(2021, 1, 16)]
4146+
4147+
ax = fig_ref.subplots()
4148+
ax.eventplot(ts_1, lineoffsets=0)
4149+
ax.eventplot(ts_2, lineoffsets=1)
4150+
4151+
ax = fig_test.subplots()
4152+
ax.eventplot([ts_1, ts_2])
4153+
4154+
41404155
@image_comparison(['marker_styles.png'], remove_text=True)
41414156
def test_marker_styles():
41424157
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)