@@ -7880,14 +7880,14 @@ def matshow(self, Z, **kwargs):
78807880 @_preprocess_data (replace_names = ["dataset" ])
78817881 def violinplot (self , dataset , positions = None , vert = True , widths = 0.5 ,
78827882 showmeans = False , showextrema = True , showmedians = False ,
7883- points = 100 , bw_method = None ):
7883+ quantiles = None , points = 100 , bw_method = None ):
78847884 """
78857885 Make a violin plot.
78867886
78877887 Make a violin plot for each column of *dataset* or each vector in
78887888 sequence *dataset*. Each filled area extends to represent the
78897889 entire data range, with optional lines at the mean, the median,
7890- the minimum, and the maximum.
7890+ the minimum, the maximum, and user-specified quantiles .
78917891
78927892 Parameters
78937893 ----------
@@ -7916,6 +7916,11 @@ def violinplot(self, dataset, positions=None, vert=True, widths=0.5,
79167916 showmedians : bool, default = False
79177917 If `True`, will toggle rendering of the medians.
79187918
7919+ quantiles : array-like, default = None
7920+ If not None, set a list of floats in interval [0, 1] for each violin,
7921+ which stands for the quantiles that will be rendered for that
7922+ violin.
7923+
79197924 points : scalar, default = 100
79207925 Defines the number of points to evaluate each of the
79217926 gaussian kernel density estimations at.
@@ -7953,6 +7958,10 @@ def violinplot(self, dataset, positions=None, vert=True, widths=0.5,
79537958 - ``cmedians``: A `~.collections.LineCollection` instance that
79547959 marks the median values of each of the violin's distribution.
79557960
7961+ - ``cquantiles``: A `~.collections.LineCollection` instance created
7962+ to identify the quantile values of each of the violin's
7963+ distribution.
7964+
79567965 """
79577966
79587967 def _kde_method (X , coords ):
@@ -7962,7 +7971,8 @@ def _kde_method(X, coords):
79627971 kde = mlab .GaussianKDE (X , bw_method )
79637972 return kde .evaluate (coords )
79647973
7965- vpstats = cbook .violin_stats (dataset , _kde_method , points = points )
7974+ vpstats = cbook .violin_stats (dataset , _kde_method , points = points ,
7975+ quantiles = quantiles )
79667976 return self .violin (vpstats , positions = positions , vert = vert ,
79677977 widths = widths , showmeans = showmeans ,
79687978 showextrema = showextrema , showmedians = showmedians )
@@ -7973,7 +7983,7 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
79737983
79747984 Draw a violin plot for each column of `vpstats`. Each filled area
79757985 extends to represent the entire data range, with optional lines at the
7976- mean, the median, the minimum, and the maximum .
7986+ mean, the median, the minimum, the maximum, and the quantiles values .
79777987
79787988 Parameters
79797989 ----------
@@ -7997,6 +8007,11 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
79978007
79988008 - ``max``: The maximum value for this violin's dataset.
79998009
8010+ Optional keys are:
8011+
8012+ - ``quantiles``: A list of scalars containing the quantile values
8013+ for this violin's dataset.
8014+
80008015 positions : array-like, default = [1, 2, ..., n]
80018016 Sets the positions of the violins. The ticks and limits are
80028017 automatically set to match the positions.
@@ -8043,13 +8058,19 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
80438058
80448059 - ``cmedians``: A `~.collections.LineCollection` instance that
80458060 marks the median values of each of the violin's distribution.
8061+
8062+ - ``cquantiles``: A `~.collections.LineCollection` instance created
8063+ to identify the quantiles values of each of the violin's
8064+ distribution.
8065+
80468066 """
80478067
80488068 # Statistical quantities to be plotted on the violins
80498069 means = []
80508070 mins = []
80518071 maxes = []
80528072 medians = []
8073+ quantiles = np .asarray ([])
80538074
80548075 # Collections to be returned
80558076 artists = {}
@@ -8106,6 +8127,10 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
81068127 mins .append (stats ['min' ])
81078128 maxes .append (stats ['max' ])
81088129 medians .append (stats ['median' ])
8130+ q = stats .get ('quantiles' )
8131+ if q is not None :
8132+ # If exist key quantiles, assume it's a list of floats
8133+ quantiles = np .concatenate ((quantiles , q ))
81098134 artists ['bodies' ] = bodies
81108135
81118136 # Render means
@@ -8129,6 +8154,22 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
81298154 pmaxes ,
81308155 colors = edgecolor )
81318156
8157+ # Render quantile values
8158+ if quantiles .size > 0 :
8159+ # Recalculate ranges for statistics lines for quantiles.
8160+ # ppmins are the left end of quantiles lines
8161+ ppmins = np .asarray ([])
8162+ # pmaxes are the right end of quantiles lines
8163+ ppmaxs = np .asarray ([])
8164+ for stats , cmin , cmax in zip (vpstats , pmins , pmaxes ):
8165+ q = stats .get ('quantiles' )
8166+ if q is not None :
8167+ ppmins = np .concatenate ((ppmins , [cmin ] * np .size (q )))
8168+ ppmaxs = np .concatenate ((ppmaxs , [cmax ] * np .size (q )))
8169+ # Start rendering
8170+ artists ['cquantiles' ] = perp_lines (quantiles , ppmins , ppmaxs ,
8171+ colors = edgecolor )
8172+
81328173 return artists
81338174
81348175 # Methods that are entirely implemented in other modules.
0 commit comments