Skip to content

Commit a2afa66

Browse files
committed
add scattermapbox font customization options
1 parent 6c8ef6d commit a2afa66

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

doc/python/scattermapbox.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.16.2
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.0
23+
version: 3.10.0
2424
plotly:
2525
description: How to make scatter plots on Mapbox maps in Python.
2626
display_as: maps
@@ -265,6 +265,65 @@ fig.show()
265265

266266
```
267267

268+
#### Font Customization
269+
270+
You can customize the font on `go.Scattermapbox` traces with `textfont`. For example, you can set the `font-family`.
271+
272+
```python
273+
import plotly.graph_objects as go
274+
275+
token = open(".mapbox_token").read() # you need your own token
276+
277+
fig = go.Figure(go.Scattermapbox(
278+
mode = "markers+text+lines",
279+
lon = [-75, -80, -50], lat = [45, 20, -20],
280+
marker = {'size': 20, 'symbol': ["bus", "harbor", "airport"]},
281+
text = ["Bus", "Harbor", "airport"], textposition = "bottom right",
282+
textfont = dict(size=18, color="black", family="Open Sans Bold")
283+
))
284+
285+
fig.update_layout(
286+
mapbox = {
287+
'accesstoken': token,
288+
'style': "outdoors", 'zoom': 0.7},
289+
showlegend = False,)
290+
291+
fig.show()
292+
```
293+
294+
`go.Scattermapbox` supports the following fonts:
295+
296+
'Metropolis Black Italic', 'Metropolis Black', 'Metropolis Bold Italic', 'Metropolis Bold', 'Metropolis Extra Bold Italic', 'Metropolis Extra Bold', 'Metropolis Extra Light Italic', 'Metropolis Extra Light', 'Metropolis Light Italic', 'Metropolis Light', 'Metropolis Medium Italic', 'Metropolis Medium', 'Metropolis Regular Italic', 'Metropolis Regular', 'Metropolis Semi Bold Italic', 'Metropolis Semi Bold', 'Metropolis Thin Italic', 'Metropolis Thin', 'Open Sans Bold Italic', 'Open Sans Bold', 'Open Sans Extrabold Italic', 'Open Sans Extrabold', 'Open Sans Italic', 'Open Sans Light Italic', 'Open Sans Light', 'Open Sans Regular', 'Open Sans Semibold Italic', 'Open Sans Semibold', 'Klokantech Noto Sans Bold', 'Klokantech Noto Sans CJK Bold', 'Klokantech Noto Sans CJK Regular', 'Klokantech Noto Sans Italic', and 'Klokantech Noto Sans Regular'.
297+
298+
299+
##### Font Weight
300+
301+
*New in 5.23*
302+
303+
You can specify a font weight on `go.Scattermapbox` with `textfont.weight`.
304+
305+
```python
306+
import plotly.graph_objects as go
307+
308+
token = open(".mapbox_token").read() # you need your own token
309+
310+
fig = go.Figure(go.Scattermapbox(
311+
mode = "markers+text+lines",
312+
lon = [-75, -80, -50], lat = [45, 20, -20],
313+
marker = dict(size=20, symbol=["bus", "harbor", "airport"]),
314+
text = ["Bus", "Harbor", "airport"], textposition = "bottom right",
315+
textfont = dict(size=18, color="black", weight=900)
316+
))
317+
318+
fig.update_layout(
319+
mapbox = dict(
320+
accesstoken=token,
321+
style="outdoors", zoom=0.7),
322+
showlegend = False,)
323+
324+
fig.show()
325+
```
326+
268327
#### Reference
269328

270329
See [function reference for `px.(scatter_mapbox)`](https://plotly.com/python-api-reference/generated/plotly.express.scatter_mapbox) or https://plotly.com/python/reference/scattermapbox/ for more information and options!

0 commit comments

Comments
 (0)