Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0e4685b

Browse filesBrowse files
authored
Merge pull request #16530 from timhoffm/fix-violinplot-pd-series
Fix violinplot support list of pandas.Series
2 parents 2e8c0c7 + 4a80e64 commit 0e4685b
Copy full SHA for 0e4685b

File tree

Expand file treeCollapse file tree

2 files changed

+12
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-0
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7782,6 +7782,8 @@ def violinplot(self, dataset, positions=None, vert=True, widths=0.5,
77827782
"""
77837783

77847784
def _kde_method(X, coords):
7785+
if hasattr(X, 'values'): # support pandas.Series
7786+
X = X.values
77857787
# fallback gracefully if the vector contains only one value
77867788
if np.all(X[0] == X):
77877789
return (X[0] == coords).astype(float)

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,6 +3068,16 @@ def test_violinplot_single_list_quantiles(fig_test, fig_ref):
30683068
ax.violinplot(data, quantiles=[[0.1, 0.3, 0.9]])
30693069

30703070

3071+
@check_figures_equal(extensions=["png"])
3072+
def test_violinplot_pandas_series(fig_test, fig_ref, pd):
3073+
np.random.seed(110433579)
3074+
s1 = pd.Series(np.random.normal(size=7), index=[9, 8, 7, 6, 5, 4, 3])
3075+
s2 = pd.Series(np.random.normal(size=9), index=list('ABCDEFGHI'))
3076+
s3 = pd.Series(np.random.normal(size=11))
3077+
fig_test.subplots().violinplot([s1, s2, s3])
3078+
fig_ref.subplots().violinplot([s1.values, s2.values, s3.values])
3079+
3080+
30713081
def test_manage_xticks():
30723082
_, ax = plt.subplots()
30733083
ax.set_xlim(0, 4)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.