Skip to content

Commit 169a9f7

Browse files
authored
Merge pull request #15172 from dstansby/backport-15166
Backport PR #15166 on branch v3.1.x
2 parents f588373 + dcb48c3 commit 169a9f7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/matplotlib/axes/_axes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2163,12 +2163,12 @@ def _convert_dx(dx, x0, xconv, convert):
21632163
# removes the units from unit packages like `pint` that
21642164
# wrap numpy arrays.
21652165
try:
2166-
x0 = x0[0]
2166+
x0 = cbook.safe_first_element(x0)
21672167
except (TypeError, IndexError, KeyError):
21682168
x0 = x0
21692169

21702170
try:
2171-
x = xconv[0]
2171+
x = cbook.safe_first_element(xconv)
21722172
except (TypeError, IndexError, KeyError):
21732173
x = xconv
21742174

lib/matplotlib/tests/test_axes.py

+8
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,14 @@ def test_bar_pandas(pd):
15921592
ax.plot(dates, baseline, color='orange', lw=4)
15931593

15941594

1595+
def test_bar_pandas_indexed(pd):
1596+
# Smoke test for indexed pandas
1597+
df = pd.DataFrame({"x": [1., 2., 3.], "width": [.2, .4, .6]},
1598+
index=[1, 2, 3])
1599+
fig, ax = plt.subplots()
1600+
ax.bar(df.x, 1., width=df.width)
1601+
1602+
15951603
@image_comparison(baseline_images=['hist_log'],
15961604
remove_text=True)
15971605
def test_hist_log():

0 commit comments

Comments
 (0)