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 b1358df

Browse filesBrowse files
donaldsolvents
authored andcommitted
Added horizontal violin plot feature compatible with means, extremas and medians.
1 parent 6f153cb commit b1358df
Copy full SHA for b1358df

File tree

Expand file treeCollapse file tree

1 file changed

+48
-13
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+48
-13
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+48-13Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6651,7 +6651,7 @@ def matshow(self, Z, **kwargs):
66516651
integer=True))
66526652
return im
66536653

6654-
def violinplot(self, dataset, positions=None, widths=0.5, showmeans=False,
6654+
def violinplot(self, dataset, positions=None, vert=True, widths=0.5, showmeans=False,
66556655
showextrema=True, showmedians=False):
66566656
"""
66576657
Make a violin plot.
@@ -6675,6 +6675,10 @@ def violinplot(self, dataset, positions=None, widths=0.5, showmeans=False,
66756675
Sets the positions of the violins. The ticks and limits are
66766676
automatically set to match the positions.
66776677
6678+
vert : bool, default = True.
6679+
If true, creates vertical violin plot
6680+
Else, creates horizontal violin plot
6681+
66786682
widths : array-like, default = 0.5
66796683
Either a scalar or a vector that sets the maximal width of
66806684
each violin. The default is 0.5, which uses about half of the
@@ -6765,30 +6769,61 @@ def violinplot(self, dataset, positions=None, widths=0.5, showmeans=False,
67656769
# correct width in the end.
67666770
v = 0.5 * w * v/v.max()
67676771

6768-
bodies += [self.fill_betweenx(coords,
6772+
# create vertical violin plot
6773+
if vert:
6774+
bodies += [self.fill_betweenx(coords,
67696775
-v+p,
67706776
v+p,
67716777
facecolor='y',
67726778
alpha=0.3)]
6779+
# create horizontal violin plot
6780+
else:
6781+
bodies += [self.fill_between(coords,
6782+
-v+p,
6783+
v+p,
6784+
facecolor='y',
6785+
alpha=0.3)]
67736786

67746787
means.append(mean)
67756788
mins.append(m)
67766789
maxes.append(M)
67776790
medians.append(median)
67786791

6779-
# Render means
6780-
if showmeans:
6781-
cmeans = self.hlines(means, pmins, pmaxes, colors='r')
6792+
# respective means, extrema median on vertical violin plot
6793+
if vert:
6794+
# Render means
6795+
if showmeans:
6796+
cmeans = self.hlines(means, pmins, pmaxes, colors='r')
6797+
6798+
# Render extrema
6799+
if showextrema:
6800+
cmaxes = self.hlines(maxes, pmins, pmaxes, colors='r')
6801+
cmins = self.hlines(mins, pmins, pmaxes, colors='r')
6802+
cbars = self.vlines(positions, mins, maxes, colors='r')
6803+
6804+
# Render medians
6805+
if showmedians:
6806+
cmedians = self.hlines(medians, pmins, pmaxes, colors='r')
6807+
6808+
# respective means, extrema median on horizontal violin plot
6809+
else:
6810+
# Render means
6811+
if showmeans:
6812+
cmeans = self.vlines(means, pmins, pmaxes, colors='r')
6813+
6814+
# Render extrema
6815+
if showextrema:
6816+
cmaxes = self.vlines(maxes, pmins, pmaxes, colors='r')
6817+
cmins = self.vlines(mins, pmins, pmaxes, colors='r')
6818+
cbars = self.hlines(positions, mins, maxes, colors='r')
6819+
6820+
# Render medians
6821+
if showmedians:
6822+
cmedians = self.vlines(medians, pmins, pmaxes, colors='r')
6823+
6824+
67826825

6783-
# Render extrema
6784-
if showextrema:
6785-
cmaxes = self.hlines(maxes, pmins, pmaxes, colors='r')
6786-
cmins = self.hlines(mins, pmins, pmaxes, colors='r')
6787-
cbars = self.vlines(positions, mins, maxes, colors='r')
67886826

6789-
# Render medians
6790-
if showmedians:
6791-
cmedians = self.hlines(medians, pmins, pmaxes, colors='r')
67926827

67936828
# Reset hold
67946829
self.hold(holdStatus)

0 commit comments

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