@@ -6725,7 +6725,7 @@ def matshow(self, Z, **kwargs):
6725
6725
integer = True ))
6726
6726
return im
6727
6727
6728
- def violinplot (self , dataset , positions = None , widths = 0.5 , showmeans = False ,
6728
+ def violinplot (self , dataset , positions = None , vert = True , widths = 0.5 , showmeans = False ,
6729
6729
showextrema = True , showmedians = False ):
6730
6730
"""
6731
6731
Make a violin plot.
@@ -6749,6 +6749,10 @@ def violinplot(self, dataset, positions=None, widths=0.5, showmeans=False,
6749
6749
Sets the positions of the violins. The ticks and limits are
6750
6750
automatically set to match the positions.
6751
6751
6752
+ vert : bool, default = True.
6753
+ If true, creates vertical violin plot
6754
+ Else, creates horizontal violin plot
6755
+
6752
6756
widths : array-like, default = 0.5
6753
6757
Either a scalar or a vector that sets the maximal width of
6754
6758
each violin. The default is 0.5, which uses about half of the
@@ -6839,30 +6843,61 @@ def violinplot(self, dataset, positions=None, widths=0.5, showmeans=False,
6839
6843
# correct width in the end.
6840
6844
v = 0.5 * w * v / v .max ()
6841
6845
6842
- bodies += [self .fill_betweenx (coords ,
6846
+ # create vertical violin plot
6847
+ if vert :
6848
+ bodies += [self .fill_betweenx (coords ,
6843
6849
- v + p ,
6844
6850
v + p ,
6845
6851
facecolor = 'y' ,
6846
6852
alpha = 0.3 )]
6853
+ # create horizontal violin plot
6854
+ else :
6855
+ bodies += [self .fill_between (coords ,
6856
+ - v + p ,
6857
+ v + p ,
6858
+ facecolor = 'y' ,
6859
+ alpha = 0.3 )]
6847
6860
6848
6861
means .append (mean )
6849
6862
mins .append (m )
6850
6863
maxes .append (M )
6851
6864
medians .append (median )
6852
6865
6853
- # Render means
6854
- if showmeans :
6855
- cmeans = self .hlines (means , pmins , pmaxes , colors = 'r' )
6866
+ # respective means, extrema median on vertical violin plot
6867
+ if vert :
6868
+ # Render means
6869
+ if showmeans :
6870
+ cmeans = self .hlines (means , pmins , pmaxes , colors = 'r' )
6871
+
6872
+ # Render extrema
6873
+ if showextrema :
6874
+ cmaxes = self .hlines (maxes , pmins , pmaxes , colors = 'r' )
6875
+ cmins = self .hlines (mins , pmins , pmaxes , colors = 'r' )
6876
+ cbars = self .vlines (positions , mins , maxes , colors = 'r' )
6877
+
6878
+ # Render medians
6879
+ if showmedians :
6880
+ cmedians = self .hlines (medians , pmins , pmaxes , colors = 'r' )
6881
+
6882
+ # respective means, extrema median on horizontal violin plot
6883
+ else :
6884
+ # Render means
6885
+ if showmeans :
6886
+ cmeans = self .vlines (means , pmins , pmaxes , colors = 'r' )
6887
+
6888
+ # Render extrema
6889
+ if showextrema :
6890
+ cmaxes = self .vlines (maxes , pmins , pmaxes , colors = 'r' )
6891
+ cmins = self .vlines (mins , pmins , pmaxes , colors = 'r' )
6892
+ cbars = self .hlines (positions , mins , maxes , colors = 'r' )
6893
+
6894
+ # Render medians
6895
+ if showmedians :
6896
+ cmedians = self .vlines (medians , pmins , pmaxes , colors = 'r' )
6897
+
6898
+
6856
6899
6857
- # Render extrema
6858
- if showextrema :
6859
- cmaxes = self .hlines (maxes , pmins , pmaxes , colors = 'r' )
6860
- cmins = self .hlines (mins , pmins , pmaxes , colors = 'r' )
6861
- cbars = self .vlines (positions , mins , maxes , colors = 'r' )
6862
6900
6863
- # Render medians
6864
- if showmedians :
6865
- cmedians = self .hlines (medians , pmins , pmaxes , colors = 'r' )
6866
6901
6867
6902
# Reset hold
6868
6903
self .hold (holdStatus )
0 commit comments