Skip to content

Commit 16880be

Browse files
committed
add methods to calculate quartiles
1 parent cfcf5f5 commit 16880be

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

doc/python/violin.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
9-
jupytext_version: 1.4.2
8+
format_version: '1.3'
9+
jupytext_version: 1.13.7
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.9.0
2424
plotly:
2525
description: How to make violin plots in Python with Plotly.
2626
display_as: statistical
@@ -274,6 +274,26 @@ fig = px.strip(df, x='day', y='tip')
274274
fig.show()
275275
```
276276

277+
### Choosing The Algorithm For Computing Quartiles
278+
279+
By default, quartiles for violin plots are computed using the `linear` method (for more about linear interpolation, see #10 listed on [http://www.amstat.org/publications/jse/v14n3/langford.html](http://www.amstat.org/publications/jse/v14n3/langford.html) and [https://en.wikipedia.org/wiki/Quartile](https://en.wikipedia.org/wiki/Quartile) for more details).
280+
281+
However, you can also choose to use an `exclusive` or an `inclusive` algorithm to compute quartiles.
282+
283+
The _exclusive_ algorithm uses the median to divide the ordered dataset into two halves. If the sample is odd, it does not include the median in either half. Q1 is then the median of the lower half and Q3 is the median of the upper half.
284+
285+
The _inclusive_ algorithm also uses the median to divide the ordered dataset into two halves, but if the sample is odd, it includes the median in both halves. Q1 is then the median of the lower half and Q3 the median of the upper half.
286+
287+
```python
288+
import plotly.express as px
289+
290+
df = px.data.tips()
291+
fig = px.violin(df, y="total_bill")
292+
fig.update_traces(quartilemethod="exclusive") # or "inclusive", or "linear" by default
293+
294+
fig.show()
295+
```
296+
277297
#### Reference
278298

279299
See [function reference for `px.violin()`](https://plotly.com/python-api-reference/generated/plotly.express.violin) or https://plotly.com/python/reference/violin/ for more information and chart attribute options!

0 commit comments

Comments
 (0)