You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/python/axes.md
+16-19Lines changed: 16 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.2'
8
+
format_version: "1.2"
9
9
jupytext_version: 1.3.0
10
10
kernelspec:
11
11
display_name: Python 3
@@ -22,7 +22,8 @@ jupyter:
22
22
pygments_lexer: ipython3
23
23
version: 3.7.3
24
24
plotly:
25
-
description: How to adjust axes properties in python. Includes examples of linear
25
+
description:
26
+
How to adjust axes properties in python. Includes examples of linear
26
27
and logarithmic axes, axes titles, styling and coloring axes and grid lines,
27
28
and more.
28
29
display_as: file_settings
@@ -34,23 +35,24 @@ jupyter:
34
35
thumbnail: thumbnail/axes.png
35
36
---
36
37
37
-
This tutorial explain how to set the properties of Cartesian axes, namely [`go.layout.XAxis`](/python/reference/#layout-xaxis) and [`go.layout.YAxis`](python/reference/#layout-xaxis). Other kinds of axes are described in other tutorials:
38
+
This tutorial explain how to set the properties of 2-dimensional Cartesian axes, namely [`go.layout.XAxis`](/python/reference/#layout-xaxis) and [`go.layout.YAxis`](python/reference/#layout-xaxis). Other kinds of axes are described in other tutorials:
39
+
38
40
-[3D axes](/python/3d-axes) The axis object is [`go.layout.Scene`](/python/reference/#layout-scene)
39
41
-[Polar axes](/python/polar-chart/). The axis object is [`go.layout.Polar`](/python/reference/#layout-polar)
40
42
-[Ternary axes](/python/ternary-plots). The axis object is [`go.layout.Ternary`](/python/reference/#layout-ternary)
41
-
-For Geo axes, see [this choropleth example](/python/choropleth-maps/#world-choropleth-map). The axis object is [`go.layout.Geo`](/python/reference/#layout-geo)
42
-
-For Mapbox axes, see the different mapbox tutorials in the [Maps page](/python/maps/). The axis object is [`go.layout.Mapbox`](/python/reference/#layout-mapbox)
43
-
- Color axes are described in the [color scales tutorial](/python/colorscales/).
43
+
-[Geo axes](/python/map-configuration/). The axis object is [`go.layout.Geo`](/python/reference/#layout-geo)
44
+
-[Mapbox axes](/python/mapbox-layers/). The axis object is [`go.layout.Mapbox`](/python/reference/#layout-mapbox)
45
+
-[Color axes](/python/colorscales/). The axis object is [`go.layout.Coloraxis`](/python/reference/#layout-coloraxis).
44
46
45
47
**See also** the tutorials on [subplots](/python/subplots) and [multiple axes](/python/multiple-axes/).
46
48
47
-
The different types of Cartesian axes are
49
+
The different types of Cartesian axes are
50
+
48
51
- 'linear'
49
52
- 'log' (see the [example below](#logarithmic-axes))
50
53
- 'date' (see the [tutorial on timeseries](/python/time-series/))
51
54
- 'category' (see for example [Bar Charts](/python/bar-charts/))
52
-
- 'multicategory' (see the [example below](#subcategory-(multicategory)-axes) ))
53
-
55
+
- 'multicategory' (see the [example below](<#subcategory-(multicategory)-axes>))
54
56
55
57
#### Logarithmic Axes
56
58
@@ -92,7 +94,7 @@ fig.show()
92
94
93
95
### Forcing an axis to be categorical
94
96
95
-
If you pass string values for the `x` or `y` parameter, plotly will automatically set the corresponding axis type to `category`, with the exception of string of numbers, in which case the axis is linear. It is however possible to force the axis type by setting explicitely `xaxis_type` to be `category`.
97
+
If you pass string values for the `x` or `y` parameter, plotly will automatically set the corresponding axis type to `category`, with the exception of string of numbers, in which case the axis is linear. It is however possible to force the axis type by setting explicitely `xaxis_type` to be `category`.
#### Toggling Axes Lines, Ticks, Labels, and Autorange
155
156
156
-
The different groups of Cartesian axes properties are
157
+
The different groups of Cartesian axes properties are
158
+
157
159
- tick values (locations of tick marks) and tick labels. Tick labels are placed at tick values.
158
160
- lines: grid lines (passing through tick values), axis lines, zero lines
159
161
- title of the axis
160
162
- range of the axis
161
163
- domain of the axis
162
164
163
-
164
165
#### Tick Placement, Color, and Style
165
166
166
167
##### Toggling axis tick marks
@@ -169,7 +170,6 @@ Axis tick marks are disabled by default for the default `plotly` theme, but they
169
170
170
171
Here is an example of turning on inside x-axis and y-axis ticks in a faceted figure created using Plotly Express. Note how the `col` argument to `update_yaxes` is used to only turn on the y-axis ticks for the left-most subplot.
The orientation of the axis tick mark labels is configured using the `tickangle` axis property. The value of `tickangle` is the angle of rotation, in the clockwise direction, of the labels from vertical in units of degrees. The font family, size, and color for the tick labels are stored under the `tickfont` axis property.
The `scaleanchor` and `scaleratio` axis properties can be used to force a fixed ratio of pixels per unit between two axes.
@@ -593,7 +590,7 @@ fig.show()
593
590
594
591
##### Decreasing the domain spanned by an axis
595
592
596
-
In the example below, the x and y axis are anchored together, and the range of the `xaxis` is set manually. By default, plotly extends the range of the axis (overriding the `range` parameter) to fit in the figure `domain`. You can restrict the `domain`to force the axis to span only the set range, by setting `constrain='domain'` as below.
593
+
In the example below, the x and y axis are anchored together, and the range of the `xaxis` is set manually. By default, plotly extends the range of the axis (overriding the `range` parameter) to fit in the figure `domain`. You can restrict the `domain` to force the axis to span only the set range, by setting `constrain='domain'` as below.
597
594
598
595
```python
599
596
import plotly.graph_objects as go
@@ -687,7 +684,7 @@ fig.show()
687
684
688
685
### Axis range for log axis type
689
686
690
-
If you are using a `log` type of axis and you want to set the range of the axis, you have to give the `log10` value of the bounds when using `fig.update_xaxes` or `fig.update_layout`. However, with `plotly.express` functions you pass directly the values of the range bounds (`plotly.express` then computes the appropriate values to pass to the figure layout).
687
+
If you are using a `log` type of axis and you want to set the range of the axis, you have to give the `log10` value of the bounds when using `fig.update_xaxes` or `fig.update_layout`. However, with `plotly.express` functions you pass directly the values of the range bounds (`plotly.express` then computes the appropriate values to pass to the figure layout).
Copy file name to clipboardExpand all lines: doc/python/bubble-maps.md
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,10 @@ jupyter:
33
33
thumbnail: thumbnail/bubble-map.jpg
34
34
---
35
35
36
+
#### Base Map Configuration
37
+
38
+
Plotly figures made with `px.scatter_geo`, `px.line_geo` or `px.choropleth` functions or containing `go.Choropleth` or `go.Scattergeo` graph objects have a `go.layout.Geo` object which can be used to [control the appearance of the base map](/python/map-configuration/) onto which data is plotted.
39
+
36
40
### Bubble map with Plotly Express
37
41
38
42
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/). With `px.scatter_geo`, each line of the dataframe is represented as a marker point. The column set as the `size` argument gives the size of markers.
Copy file name to clipboardExpand all lines: doc/python/choropleth-maps.md
+152-4Lines changed: 152 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,22 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: "1.1"
9
-
jupytext_version: 1.1.1
8
+
format_version: '1.2'
9
+
jupytext_version: 1.3.1
10
10
kernelspec:
11
11
display_name: Python 3
12
12
language: python
13
13
name: python3
14
+
language_info:
15
+
codemirror_mode:
16
+
name: ipython
17
+
version: 3
18
+
file_extension: .py
19
+
mimetype: text/x-python
20
+
name: python
21
+
nbconvert_exporter: python
22
+
pygments_lexer: ipython3
23
+
version: 3.6.8
14
24
plotly:
15
25
description: How to make choropleth maps in Python with Plotly.
16
26
display_as: maps
@@ -23,14 +33,143 @@ jupyter:
23
33
thumbnail: thumbnail/choropleth.jpg
24
34
---
25
35
26
-
A [Choropleth Map](https://en.wikipedia.org/wiki/Choropleth_map) is a heatmap using geographical boundaries. It is used to represent spatial variations of a quantity. See also the [index of other geographical charts](/python/maps/).
36
+
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).
27
37
28
-
Below we show how to create Choropleth Maps using either Plotly Express' `px.choropleth` or the lower-level `go.Choropleth`.
38
+
Below we show how to create Choropleth Maps using either Plotly Express' `px.choropleth` function or the lower-level `go.Choropleth` graph object.
39
+
40
+
#### Base Map Configuration
41
+
42
+
Plotly figures made with `px.scatter_geo`, `px.line_geo` or `px.choropleth` functions or containing `go.Choropleth` or `go.Scattergeo` graph objects have a `go.layout.Geo` object which can be used to [control the appearance of the base map](/python/map-configuration/) onto which data is plotted.
43
+
44
+
### Introduction: main parameters for choropleth outline maps
45
+
46
+
Making choropleth maps requires two main types of input:
47
+
48
+
1. Geometry information:
49
+
1. This can either be a supplied GeoJSON file where each feature has either an `id` field or some identifying value in `properties`; or
50
+
2. one of the built-in geometries within `plotly`: US states and world countries (see below)
51
+
2. A list of values indexed by feature identifier.
52
+
53
+
The GeoJSON data is passed to the `geojson` argument, and the data is passed into the `color` argument of `px.choropleth_mapbox` (`z` if using `graph_objects`), in the same order as the IDs are passed into the `location` argument.
54
+
55
+
**Note** the `geojson` attribute can also be the URL to a GeoJSON file, which can speed up map rendering in certain cases.
29
56
30
57
### Choropleth Map with plotly.express
31
58
32
59
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/).
33
60
61
+
#### GeoJSON with `feature.id`
62
+
63
+
Here we load a GeoJSON file containing the geometry information for US counties, where `feature.id` is a [FIPS code](https://en.wikipedia.org/wiki/FIPS_county_code).
64
+
65
+
```python
66
+
from urllib.request import urlopen
67
+
import json
68
+
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
69
+
counties = json.load(response)
70
+
71
+
counties["features"][0]
72
+
```
73
+
74
+
#### Data indexed by `id`
75
+
76
+
Here we load unemployment data by county, also indexed by [FIPS code](https://en.wikipedia.org/wiki/FIPS_county_code).
**Note** In this example we set `layout.geo.scope` to `usa` to automatically configure the map to display USA-centric data in an appropriate projection. See the [Geo map configuration documentation](/python/map-configuration/) for an explanation.
88
+
89
+
```python
90
+
from urllib.request import urlopen
91
+
import json
92
+
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
If the GeoJSON you are using either does not have an `id` field or you wish you use one of the keys in the `properties` field, you may use the `featureidkey` parameter to specify where to match the values of `locations`.
114
+
115
+
In the following GeoJSON object/data-file pairing, the values of `properties.district` match the values of the `district` column:
116
+
117
+
```python
118
+
import plotly.express as px
119
+
120
+
df = px.data.election()
121
+
geojson = px.data.election_geojson()
122
+
123
+
print(df["district"][2])
124
+
print(geojson["features"][0]["properties"])
125
+
```
126
+
127
+
To use them together, we set `locations` to `district` and `featureidkey` to `"properties.district"`. The `color` is set to the number of votes by the candidate named Bergeron.
128
+
129
+
**Note** In this example we set `layout.geo.visible` to `False` to hide the base map and frame, and we set `layout.geo.fitbounds` to `'locations'` to automatically zoom the map to show just the area of interest. See the [Geo map configuration documentation](/python/map-configuration/) for an explanation.
In addition to [continuous colors](/python/colorscales/), we can [discretely-color](/python/discrete-color/) our choropleth maps by setting `color` to a non-numerical column, like the name of the winner of an election.
149
+
150
+
**Note** In this example we set `layout.geo.visible` to `False` to hide the base map and frame, and we set `layout.geo.fitbounds` to `'locations'` to automatically zoom the map to show just the area of interest. See the [Geo map configuration documentation](/python/map-configuration/) for an explanation.
Plotly comes with two built-in geometries which do not require an external GeoJSON file: countries as defined in the Natural Earth dataset (see the "Cultural Base Map" section of the [Geo map configuration documentation](/python/map-configuration/) for an explanation and disclaimer) and US states.
170
+
171
+
To use the countries dataset, provide `locations` as [three-letter ISO country codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3).
Copy file name to clipboardExpand all lines: doc/python/filled-area-on-mapbox.md
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.1'
8
+
format_version: "1.1"
9
9
jupytext_version: 1.1.1
10
10
kernelspec:
11
11
display_name: Python 3
@@ -35,16 +35,16 @@ jupyter:
35
35
36
36
<!-- #region -->
37
37
38
-
### Mapbox Access Token
39
-
40
-
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.
38
+
### Mapbox Access Token and Base Map Configuration
41
39
40
+
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.
42
41
43
42
There are three different ways to show a filled area in a Mapbox map:
43
+
44
44
1. Use a [Scattermapbox](https://plot.ly/python/reference/#scattermapbox) trace and set `fill` attribute to 'toself'
45
45
2. Use a Mapbox layout (i.e. by minimally using an empty [Scattermapbox](https://plot.ly/python/reference/#scattermapbox) trace) and add a GeoJSON layer
46
46
3. Use the [Choroplethmapbox](https://plot.ly/python/mapbox-county-choropleth/) trace type
47
-
<!-- #endregion -->
47
+
<!-- #endregion -->
48
48
49
49
### Filled `Scattermapbox` Trace
50
50
@@ -140,4 +140,5 @@ fig.show()
140
140
```
141
141
142
142
#### Reference
143
+
143
144
See https://plot.ly/python/reference/#scattermapbox for more information about mapbox and their attribute options.
0 commit comments