MCPcopy Index your code
hub / github.com/plotly/plotly.py / violinplot

Function violinplot

plotly/figure_factory/_violin.py:157–193  ·  view source on GitHub ↗

Refer to FigureFactory.create_violin() for docstring.

(vals, fillcolor="#1f77b4", rugplot=True)

Source from the content-addressed store, hash-verified

155
156
157def violinplot(vals, fillcolor="#1f77b4", rugplot=True):
158 """
159 Refer to FigureFactory.create_violin() for docstring.
160 """
161 vals = np.asarray(vals, float)
162 # summary statistics
163 vals_min = calc_stats(vals)["min"]
164 vals_max = calc_stats(vals)["max"]
165 q1 = calc_stats(vals)["q1"]
166 q2 = calc_stats(vals)["q2"]
167 q3 = calc_stats(vals)["q3"]
168 d1 = calc_stats(vals)["d1"]
169 d2 = calc_stats(vals)["d2"]
170
171 # kernel density estimation of pdf
172 pdf = scipy_stats.gaussian_kde(vals)
173 # grid over the data interval
174 xx = np.linspace(vals_min, vals_max, 100)
175 # evaluate the pdf at the grid xx
176 yy = pdf(xx)
177 max_pdf = np.max(yy)
178 # distance from the violin plot to rugplot
179 distance = (2.0 * max_pdf) / 10 if rugplot else 0
180 # range for x values in the plot
181 plot_xrange = [-max_pdf - distance - 0.1, max_pdf + 0.1]
182 plot_data = [
183 make_half_violin(-yy, xx, fillcolor=fillcolor),
184 make_half_violin(yy, xx, fillcolor=fillcolor),
185 make_non_outlier_interval(d1, d2),
186 make_quartiles(q1, q3),
187 make_median(q2),
188 ]
189 if rugplot:
190 plot_data.append(
191 make_violin_rugplot(vals, max_pdf, distance=distance, color=fillcolor)
192 )
193 return plot_data, plot_xrange
194
195
196def violin_no_colorscale(

Callers 4

violin_no_colorscaleFunction · 0.85
violin_colorscaleFunction · 0.85
violin_dictFunction · 0.85
create_violinFunction · 0.85

Calls 6

calc_statsFunction · 0.85
make_half_violinFunction · 0.85
make_quartilesFunction · 0.85
make_medianFunction · 0.85
make_violin_rugplotFunction · 0.85

Tested by

no test coverage detected