Skip to content

Commit 24cf76f

Browse files
committed
Add group scatter examples
1 parent 4363c51 commit 24cf76f

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

Diff for: doc/python/line-and-scatter.md

+40-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jupyter:
88
format_version: '1.3'
99
jupytext_version: 1.14.1
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.8.8
23+
version: 3.8.0
2424
plotly:
2525
description: How to make scatter plots in Python with Plotly.
2626
display_as: basic
@@ -117,6 +117,44 @@ fig.update_traces(marker_size=10)
117117
fig.show()
118118
```
119119

120+
### Grouped Scatter Points
121+
122+
*New in 5.12*
123+
124+
By default, scatter points at the same location are overlayed on one another. We can see this in the previous example, with the values for Canada for bronze and silver. Set `scattermode='group'` to plot scatter points next to one another, centered around the shared location.
125+
126+
```python
127+
import plotly.express as px
128+
129+
df = px.data.medals_long()
130+
131+
fig = px.scatter(df, y="count", x="nation", color="medal")
132+
fig.update_traces(marker_size=10)
133+
fig.update_layout(
134+
scattermode='group',
135+
)
136+
fig.show()
137+
```
138+
139+
*New in 5.12*
140+
141+
With `scattermode='group'`, a default scattergap of `0` is used. You can configure the gap between points using `scattergap`. Here we set it to `0.75` to bring the points closer together.
142+
143+
```python
144+
import plotly.express as px
145+
146+
df = px.data.medals_long()
147+
148+
fig = px.scatter(df, y="count", x="nation", color="medal")
149+
fig.update_traces(marker_size=10)
150+
fig.update_layout(
151+
scattermode='group',
152+
scattergap=0.75
153+
)
154+
155+
fig.show()
156+
```
157+
120158
### Error Bars
121159

122160
Scatter plots support [error bars](https://plotly.com/python/error-bars/).

0 commit comments

Comments
 (0)