@@ -6651,7 +6651,7 @@ def matshow(self, Z, **kwargs):
6651
6651
integer = True ))
6652
6652
return im
6653
6653
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 ,
6655
6655
showextrema = True , showmedians = False ):
6656
6656
"""
6657
6657
Make a violin plot.
@@ -6675,6 +6675,10 @@ def violinplot(self, dataset, positions=None, widths=0.5, showmeans=False,
6675
6675
Sets the positions of the violins. The ticks and limits are
6676
6676
automatically set to match the positions.
6677
6677
6678
+ vert : bool, default = True.
6679
+ If true, creates vertical violin plot
6680
+ Else, creates horizontal violin plot
6681
+
6678
6682
widths : array-like, default = 0.5
6679
6683
Either a scalar or a vector that sets the maximal width of
6680
6684
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,
6765
6769
# correct width in the end.
6766
6770
v = 0.5 * w * v / v .max ()
6767
6771
6768
- bodies += [self .fill_betweenx (coords ,
6772
+ # create vertical violin plot
6773
+ if vert :
6774
+ bodies += [self .fill_betweenx (coords ,
6769
6775
- v + p ,
6770
6776
v + p ,
6771
6777
facecolor = 'y' ,
6772
6778
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 )]
6773
6786
6774
6787
means .append (mean )
6775
6788
mins .append (m )
6776
6789
maxes .append (M )
6777
6790
medians .append (median )
6778
6791
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
+
6782
6825
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' )
6788
6826
6789
- # Render medians
6790
- if showmedians :
6791
- cmedians = self .hlines (medians , pmins , pmaxes , colors = 'r' )
6792
6827
6793
6828
# Reset hold
6794
6829
self .hold (holdStatus )
0 commit comments