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

Skip to content

Commit c4145c5

Browse files
story645meeseeksmachine
authored andcommitted
Backport PR #21559: Fix eventplot units
1 parent ed2b1d0 commit c4145c5

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
@@ -1253,10 +1253,11 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12531253
--------
12541254
.. plot:: gallery/lines_bars_and_markers/eventplot_demo.py
12551255
"""
1256-
# We do the conversion first since not all unitized data is uniform
1257-
positions, lineoffsets, linelengths = self._process_unit_info(
1258-
[("x", positions), ("y", lineoffsets), ("y", linelengths)], kwargs)
12591256

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

1271+
poss = []
1272+
for position in positions:
1273+
poss += self._process_unit_info([("x", position)], kwargs)
1274+
positions = poss
1275+
12701276
# prevent 'singular' keys from **kwargs dict from overriding the effect
12711277
# of 'plural' keyword arguments (e.g. 'color' overriding 'colors')
12721278
colors = cbook._local_over_kwdict(colors, kwargs, 'color')
@@ -4308,9 +4314,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
43084314
43094315
"""
43104316
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
4311-
43124317
x, y = self._process_unit_info([("x", x), ("y", y)], kwargs)
4313-
43144318
# np.ma.ravel yields an ndarray, not a masked array,
43154319
# unless its argument is a masked array.
43164320
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
@@ -4116,6 +4116,21 @@ def test_eventplot_orientation(data, orientation):
41164116
plt.draw()
41174117

41184118

4119+
@check_figures_equal(extensions=['png'])
4120+
def test_eventplot_units_list(fig_test, fig_ref):
4121+
# test that list of lists converted properly:
4122+
ts_1 = [datetime.datetime(2021, 1, 1), datetime.datetime(2021, 1, 2),
4123+
datetime.datetime(2021, 1, 3)]
4124+
ts_2 = [datetime.datetime(2021, 1, 15), datetime.datetime(2021, 1, 16)]
4125+
4126+
ax = fig_ref.subplots()
4127+
ax.eventplot(ts_1, lineoffsets=0)
4128+
ax.eventplot(ts_2, lineoffsets=1)
4129+
4130+
ax = fig_test.subplots()
4131+
ax.eventplot([ts_1, ts_2])
4132+
4133+
41194134
@image_comparison(['marker_styles.png'], remove_text=True)
41204135
def test_marker_styles():
41214136
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)