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/choropleth-maps.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -208,15 +208,16 @@ fig.show()
208
208
Plotly comes with two built-in geometries which do not require an external GeoJSON file:
209
209
210
210
1. USA States
211
-
2. Countries as defined in the Natural Earth dataset.
211
+
2. Countries
212
212
213
-
**Note and disclaimer:** cultural (as opposed to physical) features are by definition subject to change, debate and dispute. Plotly includes data from Natural Earth "as-is" and defers to the [Natural Earth policy regarding disputed borders](https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/) which read:
213
+
In **Plotly.py 6.3 and later**, the built-in countries geometry is created from the following sources:
214
+
-[UN data](https://geoportal.un.org/arcgis/sharing/rest/content/items/d7caaff3ef4b4f7c82689b7c4694ad92/data) for country borders, coastlines, land, and ocean layers.
215
+
- Natural Earth data for lakes, rivers, and subunits layers.
214
216
215
-
> Natural Earth Vector draws boundaries of countries according to defacto status. We show who actually controls the situation on the ground.
217
+
In **earlier versions of Plotly.py**, the built-in countries geometry is based on Natural Earth data only. Plotly includes data from Natural Earth "as-is". This dataset draws boundaries of countries according to de facto status. See the [Natural Earth page for more details](https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/).
216
218
217
219
To use the built-in countries geometry, provide `locations` as [three-letter ISO country codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3).
Disabling the zoom in, zoom out, and autoscale buttons for specific axes is supported on cartesian axes using the `modebardisable` attribute. In the following example, the zoom in and zoom out buttons are disabled on the `xaxis`, meaning these buttons only zoom in and out on the `yaxis`. Disable the autoscale button using `modebardisable='autoscale'`. You can also disable the zoom and autoscale buttons using `modebardisable='zoominout+autoscale'`.
331
+
332
+
```python
333
+
import plotly.graph_objects as go
334
+
import plotly.data
335
+
336
+
df = plotly.data.stocks()
337
+
338
+
fig = go.Figure(
339
+
data=[
340
+
go.Scatter(
341
+
x=df['date'],
342
+
y=df['GOOG'],
343
+
mode='lines+markers',
344
+
name='Google Stock Price'
345
+
)
346
+
],
347
+
layout=go.Layout(
348
+
title='Google Stock Price Over Time with Mode Bar Disabled',
349
+
xaxis=dict(
350
+
title='Date',
351
+
# Try zooming in or out using the modebar buttons. These only apply to the yaxis in this exampe.
352
+
modebardisable='zoominout'
353
+
),
354
+
yaxis=dict(
355
+
title='Stock Price (USD)',
356
+
)
357
+
)
358
+
)
359
+
fig.show()
360
+
```
361
+
326
362
### Configuring Figures in Dash Apps
327
363
328
364
The same configuration dictionary that you pass to the `config` parameter of the `show()` method can also be passed to the [`config` property of a `dcc.Graph` component](https://dash.plotly.com/dash-core-components/graph).
Customize the title shown in unified hovermode, by specifing `unifiedhovertitle.text`.
91
+
92
+
The unified hover title is a template string that supports using variables from the data. Numbers are formatted using d3-format's syntax `%{variable:d3-format}`, for `example \"Price: %{y:$.2f}\"`. Dates are formatted using d3-time-format's syntax `%{variable|d3-time-format}`, for example `\"Day: %{2019-01-01|%A}\"`.
93
+
94
+
The following example uses `'x unified'` hover and specifies a unified hover title that shows the full weekday, month, day, and year.
95
+
96
+
```python
97
+
import plotly.graph_objects as go
98
+
import plotly.express as px
99
+
100
+
df = px.data.stocks()
101
+
102
+
fig = go.Figure(
103
+
data=[
104
+
go.Scatter(
105
+
x=df['date'],
106
+
y=df['GOOG'],
107
+
mode='lines',
108
+
name='Google'
109
+
),
110
+
go.Scatter(
111
+
x=df['date'],
112
+
y=df['AAPL'],
113
+
mode='lines',
114
+
name='Apple'
115
+
)
116
+
],
117
+
layout=go.Layout(
118
+
title_text="Stock Prices with Custom Unified Hover Title",
119
+
hovermode='x unified',
120
+
xaxis=dict(
121
+
title_text='Date',
122
+
unifiedhovertitle=dict(
123
+
text='<b>%{x|%A, %B %d, %Y}</b>'
124
+
)
125
+
),
126
+
yaxis=dict(
127
+
title_text='Price (USD)',
128
+
tickprefix='$'
129
+
)
130
+
)
131
+
)
132
+
133
+
fig.show()
134
+
135
+
```
136
+
86
137
#### Control hovermode with Dash
87
138
88
139
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash`, click "Download" to get the code and run `python app.py`.
By default, a legend can expand to fill up to half of the layout area height for a horizontal legend and the full height for a vertical legend. You can change this by specifying a `maxheight` for the legend. `maxheight` is interpreted as a ratio if it is 1 or less, and as an exact pixel value if it is greater than 1. In the following plot with many legend items, we set `maxheight` to a ratio of 0.10, giving the plot more space.
262
+
263
+
```python
264
+
import plotly.express as px
265
+
from plotly import data
266
+
267
+
df = data.gapminder().query("year==2007 and continent == 'Europe'")
268
+
269
+
fig = px.scatter(df,
270
+
x="gdpPercap",
271
+
y="lifeExp",
272
+
color="country",
273
+
size="pop",
274
+
size_max=45,
275
+
title="Life Expectancy vs. GDP per Capita in 2007 (by Country)",
276
+
labels={"gdpPercap": "GDP per Capita"},
277
+
)
278
+
279
+
fig.update_layout(
280
+
xaxis=dict(
281
+
side="top"
282
+
),
283
+
legend=dict(
284
+
orientation="h",
285
+
yanchor="bottom",
286
+
y=-0.35,
287
+
xanchor="center",
288
+
x=0.5,
289
+
maxheight=0.1, # Comment maxheight to see legend take up 0.5 of plotting area
You can control how minor log labels are displayed using the `minorloglabels` attribute. Set to `"complete"` to show complete digits, or `None` for no labels. By default, minor log labels use `"small digits"`, as shown in the previous example.
88
+
89
+
```python
90
+
import plotly.express as px
91
+
92
+
df = px.data.gapminder().query("year == 2007")
93
+
94
+
fig = px.scatter(
95
+
df, x="gdpPercap",
96
+
y="lifeExp",
97
+
hover_name="country",
98
+
log_x=True,
99
+
range_x=[1,100000],
100
+
range_y=[0,100]
101
+
)
102
+
103
+
fig.update_xaxes(
104
+
minor=dict(
105
+
ticks="inside",
106
+
ticklen=6,
107
+
showgrid=True
108
+
),
109
+
minorloglabels="complete"
110
+
)
111
+
112
+
fig.show()
113
+
```
114
+
83
115
### Logarithmic Axes with Graph Objects
84
116
85
117
If Plotly Express does not provide a good starting point, it is also possible to use [the more generic `go.Figure` class from `plotly.graph_objects`](/python/graph-objects/).
Copy file name to clipboardExpand all lines: doc/python/map-configuration.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,15 @@ Geo maps are outline-based maps. If your figure is created with a `px.scatter_ge
51
51
52
52
### Physical Base Maps
53
53
54
-
Plotly Geo maps have a built-in base map layer composed of "physical" and "cultural" (i.e. administrative border) data from the [Natural Earth Dataset](https://www.naturalearthdata.com/downloads/). Various lines and area fills can be shown or hidden, and their color and line-widths specified. In the [default `plotly` template](/python/templates/), a map frame and physical features such as a coastal outline and filled land areas are shown, at a small-scale 1:110m resolution:
54
+
Plotly Geo maps have a built-in base map layer composed of *physical* and *cultural* (i.e. administrative border) data.
55
+
56
+
In **Plotly.py 6.3 and later**, the base map layer is created from the following sources:
57
+
-[UN data](https://geoportal.un.org/arcgis/sharing/rest/content/items/d7caaff3ef4b4f7c82689b7c4694ad92/data) for country borders, coastlines, land, and oceans layers.
58
+
- Natural Earth data for lakes, rivers, and subunits layers.
59
+
60
+
In **earlier versions of Plotly.py**, the base map layer is based on Natural Earth data only. Plotly includes data from Natural Earth "as-is". This dataset draws boundaries of countries according to de facto status. See the [Natural Earth page for more details](https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/).
61
+
62
+
Various lines and area fills can be shown or hidden, and their color and line-widths specified. In the [default `plotly` template](/python/templates/), a map frame and physical features such as a coastal outline and filled land areas are shown, at a small-scale 1:110m resolution:
55
63
56
64
```python
57
65
import plotly.graph_objects as go
@@ -102,9 +110,9 @@ fig.show()
102
110
103
111
In addition to physical base map features, a "cultural" base map is included which is composed of country borders and selected sub-country borders such as states.
104
112
105
-
**Note and disclaimer:** cultural features are by definition subject to change, debate and dispute. Plotly includes data from Natural Earth "as-is" and defers to the [Natural Earth policy regarding disputed borders](https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/) which read:
113
+
In **Plotly.py 6.3 and later**, this base map is created from [UN data](https://geoportal.un.org/arcgis/sharing/rest/content/items/d7caaff3ef4b4f7c82689b7c4694ad92/data) for country borders, and Natural Earth data for sub-country borders.
106
114
107
-
> Natural Earth Vector draws boundaries of countries according to defacto status. We show who actually controls the situation on the ground.
115
+
In **earlier versions of Plotly.py**, this base map is based on Natural Earth data only. Plotly includes data from Natural Earth "as-is". This dataset draws boundaries of countries according to defacto status. See the [Natural Earth page for more details](https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/).
108
116
109
117
**To create a map with your own cultural features** please refer to our [choropleth documentation](/python/choropleth-maps/).
0 commit comments