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

Skip to content

Commit 2884058

Browse files
authored
Merge pull request #13398 from jklymak/fix-boxplot-pandas
FIX: let pandas IndexInt64 work for boxplot
2 parents e22f6e8 + 728106a commit 2884058

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,6 +4029,10 @@ def dopatch(xs, ys, **kwargs):
40294029
elif len(positions) != N:
40304030
raise ValueError(datashape_message.format("positions"))
40314031

4032+
positions = np.array(positions)
4033+
if len(positions) > 0 and not isinstance(positions[0], Number):
4034+
raise TypeError("positions should be an iterable of numbers")
4035+
40324036
# width
40334037
if widths is None:
40344038
widths = [np.clip(0.15 * np.ptp(positions), 0.15, 0.5)] * N

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,15 @@ def test_bar_timedelta():
15251525
(10, 20))
15261526

15271527

1528+
def test_boxplot_dates_pandas(pd):
1529+
# smoke test for boxplot and dates in pandas
1530+
data = np.random.rand(5, 2)
1531+
years = pd.date_range('1/1/2000',
1532+
periods=2, freq=pd.DateOffset(years=1)).year
1533+
plt.figure()
1534+
plt.boxplot(data, positions=years)
1535+
1536+
15281537
def test_bar_pandas(pd):
15291538
# Smoke test for pandas
15301539

0 commit comments

Comments
 (0)