8000 Merge pull request #15166 from jklymak/fix-indexed-pandas-bar · matplotlib/matplotlib@dcb48c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit dcb48c3

Browse files
committed
Merge pull request #15166 from jklymak/fix-indexed-pandas-bar
FIX: indexed pandas bar
1 parent f588373 commit dcb48c3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
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
B0C9 x = xconv
21742174

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
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)
0