Skip to content

Commit

Permalink
Merge pull request #4706 from plotly/maplibre-tests
Browse files Browse the repository at this point in the history
Updates for maplibre maps
  • Loading branch information
LiamConnors authored Aug 29, 2024
2 parents 601a23d + 65d97a0 commit a747fea
Show file tree
Hide file tree
Showing 30 changed files with 848 additions and 345 deletions.
4 changes: 4 additions & 0 deletions doc/apidoc/plotly.express.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ plotly's high-level API for rapid figure generation. ::
scatter_3d
scatter_polar
scatter_ternary
scatter_map
scatter_mapbox
scatter_geo
line
line_3d
line_polar
line_ternary
line_map
line_mapbox
line_geo
area
Expand All @@ -45,9 +47,11 @@ plotly's high-level API for rapid figure generation. ::
parallel_coordinates
parallel_categories
choropleth
choropleth_map
choropleth_mapbox
density_contour
density_heatmap
density_map
density_mapbox
imshow
set_mapbox_access_token
Expand Down
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/tile-map-layers/). The axis object is [`go.layout.Map`](/python/reference/layout/map/)
- [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
10 changes: 5 additions & 5 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,14 +20,14 @@ 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
language: python
layout: base
name: Bubble Maps
order: 4
order: 5
page_type: example_index
permalink: python/bubble-maps/
thumbnail: thumbnail/bubble-map.jpg
Expand Down
10 changes: 5 additions & 5 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,20 +20,20 @@ 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
language: python
layout: base
name: Choropleth Maps
order: 7
order: 8
page_type: u-guide
permalink: python/choropleth-maps/
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).

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
14 changes: 7 additions & 7 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,15 +20,15 @@ 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.
display_as: maps
language: python
layout: base
name: USA County Choropleth Maps
order: 10
order: 11
page_type: u-guide
permalink: python/county-choropleth/
thumbnail: thumbnail/county-choropleth-usa-greybkgd.jpg
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).


#### 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/)

### 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
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
Loading

0 comments on commit a747fea

Please sign in to comment.