@@ -6870,7 +6870,8 @@ def matshow(self, Z, **kwargs):
6870
6870
6871
6871
def violinplot (self , dataset , positions = None , vert = True , widths = 0.5 ,
6872
6872
showmeans = False , showextrema = True , showmedians = False ,
6873
- points = 100 , bw_method = None ):
6873
+ points = 100 , bw_method = None , color = 'y' , line_kw = {},
6874
+ ** fill_kw ):
6874
6875
"""Make a violin plot.
6875
6876
6876
6877
Call signature::
@@ -6922,6 +6923,18 @@ def violinplot(self, dataset, positions=None, vert=True, widths=0.5,
6922
6923
callable, it should take a `GaussianKDE` instance as its only
6923
6924
parameter and return a scalar. If None (default), 'scott' is used.
6924
6925
6926
+ color : color or array_like of colors, optional, default: 'y'
6927
+ Color spec or sequence of color specs, one per violin plot.
6928
+
6929
+ line_kw : dict
6930
+ :class:`matplotlib.collections.LineCollection` properties, applied
6931
+ to the lines representing the means, extrema and/or medians.
6932
+
6933
+ fill_kw : dict
6934
+ :class:`matplotlib.collections.PolyCollection` properties, applied to
6935
+ the filled area of the plot(s). Note that any keyword arguments not
6936
+ recognized above will be automatically included here.
6937
+
6925
6938
Returns
6926
6939
-------
6927
6940
@@ -6967,16 +6980,19 @@ def _kde_method(X, coords):
6967
6980
vpstats = cbook .violin_stats (dataset , _kde_method , points = points )
6968
6981
return self .violin (vpstats , positions = positions , vert = vert ,
6969
6982
widths = widths , showmeans = showmeans ,
6970
- showextrema = showextrema , showmedians = showmedians )
6983
+ showextrema = showextrema , showmedians = showmedians ,
6984
+ color = color , line_kw = line_kw , ** fill_kw )
6971
6985
6972
6986
def violin (self , vpstats , positions = None , vert = True , widths = 0.5 ,
6973
- showmeans = False , showextrema = True , showmedians = False ):
6987
+ showmeans = False , showextrema = True , showmedians = False ,
6988
+ color = 'y' , line_kw = {}, ** fill_kw ):
6974
6989
"""Drawing function for violin plots.
6975
6990
6976
6991
Call signature::
6977
6992
6978
6993
violin(vpstats, positions=None, vert=True, widths=0.5,
6979
- showmeans=False, showextrema=True, showmedians=False):
6994
+ showmeans=False, showextrema=True, showmedians=False,
6995
+ colors='y'):
6980
6996
6981
6997
Draw a violin plot for each column of `vpstats`. Each filled area
6982
6998
extends to represent the entire data range, with optional lines at the
@@ -7026,6 +7042,18 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
7026
7042
showmedians : bool, default = False
7027
7043
If true, will toggle rendering of the medians.
7028
7044
7045
+ color : color or array_like of colors, optional, default: 'y'
7046
+ Color spec or sequence of color specs, one per violin plot.
7047
+
7048
+ line_kw : dict
7049
+ :class:`matplotlib.collections.LineCollection` properties, applied
7050
+ to the lines representing the means, extrema and/or medians.
7051
+
7052
+ fill_kw : dict
7053
+ :class:`matplotlib.collections.PolyCollection` properties, applied to
7054
+ the filled area of the plot(s). Note that any keyword arguments not
7055
+ recognized above will be automatically included here.
7056
+
7029
7057
Returns
7030
7058
-------
7031
7059
result : dict
@@ -7089,6 +7117,16 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
7089
7117
elif len (widths ) != N :
7090
7118
raise ValueError (datashape_message .format ("widths" ))
7091
7119
7120
+ # Validate colors
7121
+ if np .isscalar (color ):
7122
+ color = [color ] * N
7123
+ elif len (color ) != N :
7124
+ raise ValueError (datashape_message .format ("color" ))
7125
+
7126
+ # original default values for line color and alpha
7127
+ line_color = line_kw .pop ('colors' , 'r' )
7128
+ alpha = fill_kw .pop ('alpha' , 0.3 )
7129
+
7092
7130
# Calculate ranges for statistics lines
7093
7131
pmins = - 0.25 * np .array (widths ) + positions
7094
7132
pmaxes = 0.25 * np .array (widths ) + positions
@@ -7105,16 +7143,17 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
7105
7143
7106
7144
# Render violins
7107
7145
bodies = []
7108
- for stats , pos , width in zip (vpstats , positions , widths ):
7146
+ for stats , pos , width , c in zip (vpstats , positions , widths , color ):
7109
7147
# The 0.5 factor reflects the fact that we plot from v-p to
7110
7148
# v+p
7111
7149
vals = np .array (stats ['vals' ])
7112
7150
vals = 0.5 * width * vals / vals .max ()
7113
7151
bodies += [fill (stats ['coords' ],
7114
7152
- vals + pos ,
7115
7153
vals + pos ,
7116
- facecolor = 'y' ,
7117
- alpha = 0.3 )]
7154
+ facecolor = c ,
7155
+ alpha = alpha ,
7156
+ ** fill_kw )]
7118
7157
means .append (stats ['mean' ])
7119
7158
mins .append (stats ['min' ])
7120
7159
maxes .append (stats ['max' ])
@@ -7123,20 +7162,22 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
7123
7162
7124
7163
# Render means
7125
7164
if showmeans :
7126
- artists ['cmeans' ] = perp_lines (means , pmins , pmaxes , colors = 'r' )
7165
+ artists ['cmeans' ] = perp_lines (means , pmins , pmaxes ,
7166
+ colors = line_color , ** line_kw )
7127
7167
7128
7168
# Render extrema
7129
7169
if showextrema :
7130
- artists ['cmaxes' ] = perp_lines (maxes , pmins , pmaxes , colors = 'r' )
7131
- artists ['cmins' ] = perp_lines (mins , pmins , pmaxes , colors = 'r' )
7132
- artists ['cbars' ] = par_lines (positions , mins , maxes , colors = 'r' )
7170
+ artists ['cmaxes' ] = perp_lines (maxes , pmins , pmaxes ,
7171
+ colors = line_color , ** line_kw )
7172
+ artists ['cmins' ] = perp_lines (mins , pmins , pmaxes ,
7173
+ colors = line_color , ** line_kw )
7174
+ artists ['cbars' ] = par_lines (positions , mins , maxes ,
7175
+ colors = line_color , ** line_kw )
7133
7176
7134
7177
# Render medians
7135
7178
if showmedians :
7136
- artists ['cmedians' ] = perp_lines (medians ,
7137
- pmins ,
7138
- pmaxes ,
7139
- colors = 'r' )
7179
+ artists ['cmedians' ] = perp_lines (medians , pmins , pmaxes ,
7180
+ colors = line_color , ** line_kw )
7140
7181
7141
7182
return artists
7142
7183
0 commit comments