Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for maplibre maps #4706

Merged
merged 45 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a4a785e
remove mapbox reference
LiamConnors Jul 26, 2024
a913463
update to new map types
LiamConnors Jul 26, 2024
76f6756
fix typo
LiamConnors Jul 26, 2024
608d114
update choropleth for maplibre changes
LiamConnors Jul 26, 2024
9dc8202
add new map types
LiamConnors Jul 26, 2024
4a70af6
update density heatmaps + fix typo
LiamConnors Jul 26, 2024
2e0f184
Update scattermapbox.md
LiamConnors Jul 26, 2024
3b581e6
various updates for new map traces
LiamConnors Jul 30, 2024
b90f6ea
small edits
LiamConnors Aug 1, 2024
8e2538d
update map layers doc
LiamConnors Aug 3, 2024
671c80d
add stamen example
LiamConnors Aug 3, 2024
4b382e3
updates for new maps
LiamConnors Aug 3, 2024
b849b38
add deprecation notice
LiamConnors Aug 6, 2024
58b3e61
Update doc/python/scattermapbox.md
LiamConnors Aug 6, 2024
bce8097
fix code errors
LiamConnors Aug 7, 2024
fdae821
Update datashader.md
LiamConnors Aug 7, 2024
022b995
Update filled-area-on-mapbox.md
LiamConnors Aug 7, 2024
7983874
Update line-charts.md
LiamConnors Aug 7, 2024
614e37e
Update doc/python/map-configuration.md
LiamConnors Aug 7, 2024
31fde09
update symbol
LiamConnors Aug 7, 2024
ef80408
Update heatmaps.md
LiamConnors Aug 7, 2024
8fcb2bf
Update hover-text-and-formatting.md
LiamConnors Aug 7, 2024
fa931e4
Update hover-text-and-formatting.md
LiamConnors Aug 7, 2024
1ffb776
add links
LiamConnors Aug 7, 2024
10c5104
Merge branch 'master' into maplibre-tests
LiamConnors Aug 8, 2024
155f434
add map to doc/apidoc/plotly.express.rst
archmoj Aug 6, 2024
72bacb5
new map subplots & traces to px, etc.
archmoj Aug 6, 2024
ba9c413
update plotly.js v2.34.0-327-g056799dfc
archmoj Aug 23, 2024
e994f13
Update doc/python/mapbox-density-heatmaps.md
LiamConnors Aug 27, 2024
b7aff21
Update doc/python/mapbox-density-heatmaps.md
LiamConnors Aug 27, 2024
b0c45b3
Add migration guide
ndrezn Aug 27, 2024
e243e6d
Update packages/python/plotly/plotly/express/_doc.py
archmoj Aug 27, 2024
7e2eefc
update descriptions
archmoj Aug 28, 2024
8872f0b
Update doc/python/figure-structure.md
LiamConnors Aug 28, 2024
792a5e9
Update doc/python/migrate-to-maplibre.md
ndrezn Aug 28, 2024
af83303
Update doc/python/migrate-to-maplibre.md
ndrezn Aug 28, 2024
376c6db
Remove redirect
ndrezn Aug 28, 2024
fd12157
Update doc/python/axes.md
LiamConnors Aug 29, 2024
2bd7dc6
Add perma links for style comparisons
ndrezn Aug 29, 2024
4fc6d81
Revert "update plotly.js v2.34.0-327-g056799dfc"
LiamConnors Aug 29, 2024
24730c3
Merge pull request #4726 from plotly/maplibre-tests_with-px
LiamConnors Aug 29, 2024
38afbf0
Merge branch 'master' into maplibre-tests
LiamConnors Aug 29, 2024
a1c7f88
Merge branch 'master' into maplibre-tests
LiamConnors Aug 29, 2024
f34d599
fix metadata
LiamConnors Aug 29, 2024
65d97a0
Merge branch 'maplibre-tests' of https://github.com/plotly/plotly.py …
LiamConnors Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/python/axes.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Other kinds of subplots and axes are described in other tutorials:
- [Polar axes](/python/polar-chart/). The axis object is [`go.layout.Polar`](/python/reference/layout/polar/)
- [Ternary axes](/python/ternary-plots). The axis object is [`go.layout.Ternary`](/python/reference/layout/ternary/)
- [Geo axes](/python/map-configuration/). The axis object is [`go.layout.Geo`](/python/reference/layout/geo/)
- [Mapbox axes](/python/mapbox-layers/). The axis object is [`go.layout.Mapbox`](/python/reference/layout/mapbox/)
- [Map axes](/python/map-layers/). The axis object is [`go.layout.Map`](/python/reference/layout/map/)
LiamConnors marked this conversation as resolved.
Show resolved Hide resolved
LiamConnors marked this conversation as resolved.
Show resolved Hide resolved
- [Color axes](/python/colorscales/). The axis object is [`go.layout.Coloraxis`](/python/reference/layout/coloraxis/).

**See also** the tutorials on [facet plots](/python/facet-plots/), [subplots](/python/subplots) and [multiple axes](/python/multiple-axes/).
Expand Down
8 changes: 4 additions & 4 deletions doc/python/bubble-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ jupyter:
text_representation:
extension: .md
format_name: markdown
format_version: '1.1'
jupytext_version: 1.1.1
format_version: '1.3'
jupytext_version: 1.16.3
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.6.7
version: 3.10.0
plotly:
description: How to make bubble maps in Python with Plotly.
display_as: maps
Expand Down
8 changes: 4 additions & 4 deletions doc/python/choropleth-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.3'
jupytext_version: 1.14.1
jupytext_version: 1.16.3
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.8.8
version: 3.10.0
plotly:
description: How to make choropleth maps in Python with Plotly.
display_as: maps
Expand All @@ -33,7 +33,7 @@ jupyter:
thumbnail: thumbnail/choropleth.jpg
---

A [Choropleth Map](https://en.wikipedia.org/wiki/Choropleth_map) is a map composed of colored polygons. It is used to represent spatial variations of a quantity. This page documents how to build **outline** choropleth maps, but you can also build [choropleth **tile maps** using our Mapbox trace types](/python/mapbox-county-choropleth).
A [Choropleth Map](https://en.wikipedia.org/wiki/Choropleth_map) is a map composed of colored polygons. It is used to represent spatial variations of a quantity. This page documents how to build **outline** choropleth maps, but you can also build [choropleth **tile maps**](/python/tile-county-choropleth).
gvwilson marked this conversation as resolved.
Show resolved Hide resolved

Below we show how to create Choropleth Maps using either Plotly Express' `px.choropleth` function or the lower-level `go.Choropleth` graph object.

Expand Down
12 changes: 6 additions & 6 deletions doc/python/county-choropleth.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ jupyter:
text_representation:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.3.1
format_version: '1.3'
jupytext_version: 1.16.3
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.6.8
version: 3.10.0
plotly:
description: How to create colormaped representations of USA counties by FIPS
values in Python.
Expand All @@ -37,7 +37,7 @@ jupyter:
### Deprecation warning


This page describes a [legacy "figure factory" method](/python/figure-factories/) for creating map-like figures using [self-filled scatter traces](/python/shapes). **This is no longer the recommended way to make county-level choropleth maps**, instead we recommend using a [GeoJSON-based approach to making outline choropleth maps](/python/choropleth-maps/) or the alternative [Mapbox tile-based choropleth maps](/python/mapbox-county-choropleth).
This page describes a [legacy "figure factory" method](/python/figure-factories/) for creating map-like figures using [self-filled scatter traces](/python/shapes). **This is no longer the recommended way to make county-level choropleth maps**, instead we recommend using a [GeoJSON-based approach to making outline choropleth maps](/python/choropleth-maps/) or the alternative [tile-based choropleth maps](/python/tile-county-choropleth).
gvwilson marked this conversation as resolved.
Show resolved Hide resolved


#### Required Packages
Expand Down Expand Up @@ -274,7 +274,7 @@ fig.layout.template = None
fig.show()
```

Also see Mapbox county choropleths made in Python: [https://plotly.com/python/mapbox-county-choropleth/](https://plotly.com/python/mapbox-county-choropleth/)
Also see tile county choropleths made in Python: [https://plotly.com/python/tile-county-choropleth/](https://plotly.com/python/tile-county-choropleth/)
gvwilson marked this conversation as resolved.
Show resolved Hide resolved

### Reference

Expand Down
34 changes: 13 additions & 21 deletions doc/python/datashader.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ jupyter:
text_representation:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.3.0
format_version: '1.3'
jupytext_version: 1.16.3
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.7.3
version: 3.10.0
plotly:
description: How to use datashader to rasterize large datasets, and visualize
the generated raster data with plotly.
Expand All @@ -36,10 +36,10 @@ jupyter:

[datashader](https://datashader.org/) creates rasterized representations of large datasets for easier visualization, with a pipeline approach consisting of several steps: projecting the data on a regular grid, creating a color representation of the grid, etc.

### Passing datashader rasters as a mapbox image layer
### Passing datashader rasters as a tile map image layer

We visualize here the spatial distribution of taxi rides in New York City. A higher density
is observed on major avenues. For more details about mapbox charts, see [the mapbox layers tutorial](/python/mapbox-layers). No mapbox token is needed here.
is observed on major avenues. For more details about tile-based maps, see [the tile map layers tutorial](/python/tile-map-layers).

```python
import pandas as pd
Expand All @@ -51,7 +51,7 @@ cvs = ds.Canvas(plot_width=1000, plot_height=1000)
agg = cvs.points(dff, x='Lon', y='Lat')
# agg is an xarray object, see http://xarray.pydata.org/en/stable/ for more details
coords_lat, coords_lon = agg.coords['Lat'].values, agg.coords['Lon'].values
# Corners of the image, which need to be passed to mapbox
# Corners of the image
coordinates = [[coords_lon[0], coords_lat[0]],
[coords_lon[-1], coords_lat[0]],
[coords_lon[-1], coords_lat[-1]],
Expand All @@ -62,16 +62,12 @@ import datashader.transfer_functions as tf
img = tf.shade(agg, cmap=fire)[::-1].to_pil()

import plotly.express as px
# Trick to create rapidly a figure with mapbox axes
fig = px.scatter_mapbox(dff[:1], lat='Lat', lon='Lon', zoom=12)
# Add the datashader image as a mapbox layer image
fig.update_layout(mapbox_style="carto-darkmatter",
mapbox_layers = [
{
"sourcetype": "image",
"source": img,
"coordinates": coordinates
}]
# Trick to create rapidly a figure with map axes
archmoj marked this conversation as resolved.
Show resolved Hide resolved
fig = px.scatter_map(dff[:1], lat='Lat', lon='Lon', zoom=12)
# Add the datashader image as a tile map layer image
fig.update_layout(
map_style="carto-darkmatter",
map_layers=[{"sourcetype": "image", "source": img, "coordinates": coordinates}],
)
fig.show()
```
Expand Down Expand Up @@ -113,7 +109,3 @@ fig.update_traces(hoverongaps=False)
fig.update_layout(coloraxis_colorbar=dict(title='Count', tickprefix='1.e'))
fig.show()
```

```python

```
12 changes: 6 additions & 6 deletions doc/python/figure-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The second of the three top-level attributes of a figure is `layout`, whose valu
* Subplots of various types on which can be drawn multiple traces and which are positioned in paper coordinates:
* `xaxis`, `yaxis`, `xaxis2`, `yaxis3` etc: X and Y cartesian axes, the intersections of which are cartesian subplots
* `scene`, `scene2`, `scene3` etc: 3d scene subplots
* `ternary`, `ternary2`, `ternary3`, `polar`, `polar2`, `polar3`, `geo`, `geo2`, `geo3`, `mapbox`, `mapbox2`, `mabox3`, `smith`, `smith2` etc: ternary, polar, geo, mapbox or smith subplots
* `ternary`, `ternary2`, `ternary3`, `polar`, `polar2`, `polar3`, `geo`, `geo2`, `geo3`, `map`, `map2`, `map3`, `smith`, `smith2` etc: ternary, polar, geo, map or smith subplots
* Non-data marks which can be positioned in paper coordinates, or in data coordinates linked to 2d cartesian subplots:
* `annotations`: [textual annotations with or without arrows](/python/text-and-annotations/)
* `shapes`: [lines, rectangles, ellipses or open or closed paths](/python/shapes/)
Expand Down Expand Up @@ -181,18 +181,18 @@ The following trace types are compatible with smith subplots via the `smith` att

### Map Trace Types and Subplots

Figures can include two different types of map subplots: [geo subplots for outline maps](/python/map-configuration/) and [mapbox subplots for tile maps](/python/mapbox-layers/). The following trace types support attributes named `geo` or `mapbox`, whose values must refer to corresponding objects in the layout i.e. `geo="geo2"` etc. Note that attributes such as `layout.geo2` and `layout.mapbox` etc do not have to be explicitly defined, in which case default values will be inferred. Multiple traces of a compatible type can be placed on the same subplot.
Figures can include two different types of map subplots: [geo subplots for outline maps](/python/map-configuration/) and [tile-based maps](/python/tile-map-layers/). The following trace types support attributes named `geo` or `map`, whose values must refer to corresponding objects in the layout i.e. `geo="geo2"` etc. Note that attributes such as `layout.geo2` and `layout.map` etc do not have to be explicitly defined, in which case default values will be inferred. Multiple traces of a compatible type can be placed on the same subplot.

The following trace types are compatible with geo subplots via the `geo` attribute:

* [`scattergeo`](/python/scatter-plots-on-maps/), which can be used to draw [individual markers](/python/scatter-plots-on-maps/), [line and curves](/python/lines-on-maps/) and filled areas on outline maps
* [`choropleth`](/python/choropleth-maps/): [colored polygons](/python/choropleth-maps/) on outline maps

The following trace types are compatible with mapbox subplots via the `mapbox` attribute:
The following trace types are compatible with tile map subplots via the `map` attribute:

* [`scattermapbox`](/python/scattermapbox/), which can be used to draw [individual markers](/python/scattermapbox/), [lines and curves](/python/lines-on-mapbox/) and [filled areas](/python/filled-area-on-mapbox/) on tile maps
* [`choroplethmapbox`](/python/mapbox-county-choropleth/): colored polygons on tile maps
* [`densitymapbox`](/python/mapbox-density-heatmaps/): density heatmaps on tile maps
* [`scattermap`](/python/tile-scatter-maps/), which can be used to draw [individual markers](/python/tile-scatter-maps/), [lines and curves](/python/lines-on-tile-maps/) and [filled areas](/python/filled-area-tile-maps/) on tile maps
* [`choroplethmap`](/python/tile-county-choropleth/): colored polygons on tile maps
* [`densitymap`](/python/tile-density-heatmaps/): density heatmaps on tile maps

### Traces Which Are Their Own Subplots

Expand Down
81 changes: 53 additions & 28 deletions doc/python/filled-area-on-mapbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ jupyter:
text_representation:
extension: .md
format_name: markdown
format_version: '1.1'
jupytext_version: 1.1.1
format_version: '1.3'
jupytext_version: 1.16.3
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
Expand All @@ -20,68 +20,63 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.6.8
version: 3.10.0
plotly:
description: How to make an area on Map in Python with Plotly.
description: How to make an area on tile-based maps in Python with Plotly.
display_as: maps
language: python
layout: base
name: Filled Area on Maps
order: 3
page_type: example_index
permalink: python/filled-area-on-mapbox/
permalink: python/filled-area-tile-maps/
redirect_from: python/filled-area-on-mapbox/
thumbnail: thumbnail/area.jpg
---

<!-- #region -->

### Mapbox Access Token and Base Map Configuration

To plot on Mapbox maps with Plotly you _may_ need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/python/mapbox-layers/) documentation for more information.
There are three different ways to show a filled area on a tile-based map:

There are three different ways to show a filled area in a Mapbox map:
- Using a [Scattermap](https://plotly.com/python/reference/scattermap/) trace and setting the `fill` attribute to 'toself'
- Using a map layout (i.e. by minimally using an empty [Scattermap](https://plotly.com/python/reference/scattermap/) trace) and adding a GeoJSON layer
- Using the [Choroplethmap](https://plotly.com/python/tile-county-choropleth/) trace type

1. Use a [Scattermapbox](https://plotly.com/python/reference/scattermapbox/) trace and set `fill` attribute to 'toself'
2. Use a Mapbox layout (i.e. by minimally using an empty [Scattermapbox](https://plotly.com/python/reference/scattermapbox/) trace) and add a GeoJSON layer
3. Use the [Choroplethmapbox](https://plotly.com/python/mapbox-county-choropleth/) trace type
<!-- #endregion -->
## Filled `Scattermap` Trace

### Filled `Scattermapbox` Trace

The following example uses `Scattermapbox` and sets `fill = 'toself'`
The following example uses `Scattermap` and sets `fill = 'toself'`

```python
import plotly.graph_objects as go

fig = go.Figure(go.Scattermapbox(
fig = go.Figure(go.Scattermap(
fill = "toself",
lon = [-74, -70, -70, -74], lat = [47, 47, 45, 45],
marker = { 'size': 10, 'color': "orange" }))

fig.update_layout(
mapbox = {
map = {
'style': "open-street-map",
'center': {'lon': -73, 'lat': 46 },
'zoom': 5},
showlegend = False)

fig.show()

```

### Multiple Filled Areas with a `Scattermapbox` trace
### Multiple Filled Areas with a `Scattermap` trace

The following example shows how to use `None` in your data to draw multiple filled areas. Such gaps in trace data are unconnected by default, but this can be controlled via the [connectgaps](https://plotly.com/python/reference/scattermapbox/#scattermapbox-connectgaps) attribute.
The following example shows how to use `None` in your data to draw multiple filled areas. Such gaps in trace data are unconnected by default, but this can be controlled via the [connectgaps](https://plotly.com/python/reference/scattermap/#scattermap-connectgaps) attribute.

```python
import plotly.graph_objects as go

fig = go.Figure(go.Scattermapbox(
fig = go.Figure(go.Scattermap(
mode = "lines", fill = "toself",
lon = [-10, -10, 8, 8, -10, None, 30, 30, 50, 50, 30, None, 100, 100, 80, 80, 100],
lat = [30, 6, 6, 30, 30, None, 20, 30, 30, 20, 20, None, 40, 50, 50, 40, 40]))

fig.update_layout(
mapbox = {'style': "open-street-map", 'center': {'lon': 30, 'lat': 30}, 'zoom': 2},
map = {'style': "open-street-map", 'center': {'lon': 30, 'lat': 30}, 'zoom': 2},
showlegend = False,
margin = {'l':0, 'r':0, 'b':0, 't':0})

Expand All @@ -95,13 +90,13 @@ In this map we add a GeoJSON layer.
```python
import plotly.graph_objects as go

fig = go.Figure(go.Scattermapbox(
fig = go.Figure(go.Scattermap(
mode = "markers",
lon = [-73.605], lat = [45.51],
marker = {'size': 20, 'color': ["cyan"]}))

fig.update_layout(
mapbox = {
map = {
'style': "open-street-map",
'center': { 'lon': -73.6, 'lat': 45.5},
'zoom': 12, 'layers': [{
Expand Down Expand Up @@ -139,6 +134,36 @@ fig.update_layout(
fig.show()
```

<!-- #region -->
### Mapbox Maps

> Mapbox traces are deprecated and may be removed in a future version of Plotly.py.

The earlier examples using `go.Scattermap` use [Maplibre](https://maplibre.org/maplibre-gl-js/docs/) for rendering. This trace was introduced in Plotly.py 5.24 and is now the recommended way to draw filled areas on tile-based maps. There is also a trace that uses [Mapbox](https://docs.mapbox.com), called `go.Scattermapbox`.

To use the `Scattermapbox` trace type, in some cases you _may_ need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/python/mapbox-layers/) documentation for more information.

Here's one of the earlier examples rewritten to use `Scattermapbox`.

```python
import plotly.graph_objects as go

fig = go.Figure(go.Scattermapbox(
fill = "toself",
lon = [-74, -70, -70, -74], lat = [47, 47, 45, 45],
marker = { 'size': 10, 'color': "orange" }))

fig.update_layout(
mapbox = {
'style': "open-street-map",
'center': {'lon': -73, 'lat': 46 },
'zoom': 5},
showlegend = False)

fig.show()
```
<!-- #endregion -->

#### Reference

See https://plotly.com/python/reference/scattermapbox/ for more information about mapbox and their attribute options.
See https://plotly.com/python/reference/scattermap/ for available attribute options, or for `go.Scattermapbox`, see https://plotly.com/python/reference/scattermapbox/.
2 changes: 1 addition & 1 deletion doc/python/heatmaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jupyter:
thumbnail: thumbnail/heatmap.jpg
---

The term "heatmap" usually refers to a cartesian plot with data visualized as colored rectangular tiles, which is the subject of this page. It is also sometimes used to refer to [actual maps with density data displayed as color intensity](/python/mapbox-density-heatmaps/).
The term "heatmap" usually refers to a Cartesian plot with data visualized as colored rectangular tiles, which is the subject of this page. It is also sometimes used to refer to [actual maps with density data displayed as color intensity](/python/tile-density-heatmaps/).

Plotly supports two different types of colored-tile heatmaps:

Expand Down
Loading