Skip to content

Commit bb046b7

Browse files
authored
Merge pull request #1466 from plotly/choropleth
js choropleth mapbox
2 parents 32265ac + 404307b commit bb046b7

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: Dark tile, Needs Token
3+
plot_url: https://codepen.io/plotly/embed/eYOdVRG/?height=527&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: choropleth-mapbox
6+
order: 3
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
This example uses [zmin and zmax](https://plot.ly/javascript/reference/#choroplethmapbox-zmin) to define the lower bound and upper bound of the color domain. If these attributes are not set, Plotly [determines the color domain](https://plot.ly/javascript/reference/#heatmap-zauto) based on the input data.
11+
---
12+
13+
var data = [{
14+
type: "choroplethmapbox", name: "US states", geojson: "https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/us-states.json", locations: [ "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY" ],
15+
z: [ 141, 140, 155, 147, 132, 146, 151, 137, 146, 136, 145, 141, 149, 151, 138, 158, 164, 141, 146, 145, 142, 150, 155, 160, 156, 161, 147, 164, 150, 152, 155, 167, 145, 146, 151, 154, 161, 145, 155, 150, 151, 162, 172, 169, 170, 151, 152, 173, 160, 176 ],
16+
zmin: 25, zmax: 280, colorbar: {y: 0, yanchor: "bottom", title: {text: "US states", side: "right"}}}
17+
];
18+
19+
var layout = {mapbox: {style: "dark", center: {lon: -110, lat: 50}, zoom: 0.8}, width: 600, height: 400, margin: {t: 0, b: 0}};
20+
21+
var config = {mapboxAccessToken: 'add your access token'};
22+
23+
Plotly.newPlot('graph', data, layout, config);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Basic Tile, Needs Token
3+
plot_url: https://codepen.io/plotly/embed/BaBLYZN/?height=505&theme-id=15263&default-tab=result\
4+
language: plotly_js
5+
suite: choropleth-mapbox
6+
order: 1
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
11+
This tutorial uses [Mapbox GL JS](https://docs.mapbox.com/mapbox-gl-js/api/) to make a map of US states using [vector tiles](https://plot.ly/javascript/mapbox-layers/).
12+
---
13+
14+
var data = [{
15+
type: "choroplethmapbox", locations: ["NY", "MA", "VT"], z: [-50, -10, -20],
16+
geojson: "https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/us-states.json"
17+
}];
18+
19+
var layout = {mapbox: {center: {lon: -74, lat: 43}, zoom: 3.5},
20+
width: 600, height:400};
21+
22+
var config = {mapboxAccessToken: "your access token"};
23+
24+
Plotly.newPlot('graph', data, layout, config);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Streets Tile, Needs Token
3+
plot_url: https://codepen.io/plotly/embed/NWKRygN/?height=510&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: choropleth-mapbox
6+
order: 2
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
11+
The following example sets `geojson object` of type `feature` and geometries of type 'Polygon'. For more information see [geojson attribute](https://plot.ly/javascript/reference/#choroplethmapbox-geojson) in the reference page.
12+
As you see, scattermapbox trace is above Choropleth mapbox. To set the Choropleth mapbox above all the other traces you should set [below attribute](https://plot.ly/javascript/reference/#choroplethmapbox-below).
13+
---
14+
var data = [
15+
{type: "scattermapbox", lon: [-86], lat: [34], marker: {size: 20, color: 'purple'}},
16+
{
17+
type: "choroplethmapbox",locations: ["AL"], z: [10], coloraxis: "coloraxis", geojson: {type: "Feature", id: "AL", geometry: {type: "Polygon", coordinates: [[
18+
[-86, 35], [-85, 34], [-85, 32], [-85, 32], [-85, 32], [-85, 32], [-85, 31],
19+
[-86, 31], [-87, 31], [-87, 31], [-88, 30], [-88, 30], [-88, 30], [-88, 30],
20+
[-88, 34], [-88, 35]]]
21+
}}}];
22+
23+
var layout = {width: 600, height: 400, mapbox: {style: 'streets',
24+
center: {lon: -86, lat: 33}, zoom: 5}, marker: {line: {color: "blue"}},
25+
coloraxis: {showscale: false, colorscale: "Viridis"}};
26+
27+
Plotly.setPlotConfig({mapboxAccessToken: 'add your access token'});
28+
29+
Plotly.newPlot('graph', data, layout);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: JavaScript Graphing Library D3.js-based Choropleth Mapbox | Examples | Plotly
3+
name: Choropleth Mapbox
4+
permalink: javascript/choropleth-mapbox/
5+
description: How to make a D3.js-based choropleth mapbox in JavaScript. A Choropleth mapbox shades geographic regions by value.
6+
layout: user-guide
7+
thumbnail: thumbnail/mapbox-choropleth.png
8+
language: plotly_js
9+
page_type: example_index
10+
has_thumbnail: true
11+
display_as: maps
12+
order: 0
13+
redirect_from: javascript-graphing-library/choropleth-mapbox/
14+
---
15+
{% assign examples = site.posts | where:"language","plotly_js" | where:"suite","choropleth-mapbox" | sort: "order" %}
16+
{% include auto_examples.html examples=examples %}

0 commit comments

Comments
 (0)