Skip to content

Commit c94d6af

Browse files
authored
Merge pull request #5269 from plotly/docs-update-next-release
Add docs updates for Plotly.py v6.3
2 parents 1f2e4bc + c7a38b6 commit c94d6af

File tree

8 files changed

+270
-21
lines changed

8 files changed

+270
-21
lines changed

doc/python/axes.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.16.3
9+
jupytext_version: 1.17.2
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.10.14
23+
version: 3.9.0
2424
plotly:
2525
description: How to adjust axes properties in Python - axes titles, styling and
2626
coloring axes and grid lines, ticks, tick labels and more.
@@ -619,6 +619,38 @@ fig.update_yaxes(zeroline=True, zerolinewidth=2, zerolinecolor='LightPink')
619619
fig.show()
620620
```
621621

622+
##### Controlling Zero Line Layer
623+
624+
*New in 6.3*
625+
626+
By default, zero lines are displayed below traces. Set `zerolinelayer="above traces"` on an axis to display its zero line above traces:
627+
628+
```python
629+
import plotly.graph_objects as go
630+
631+
x = ['A', 'B', 'C', 'D', 'A']
632+
y = [2, 0, 4, -3, 2]
633+
634+
fig = go.Figure(
635+
data=[
636+
go.Scatter(
637+
x=x,
638+
y=y,
639+
fill='toself',
640+
mode='none',
641+
fillcolor='lightpink'
642+
)
643+
],
644+
layout=dict(
645+
yaxis=dict(
646+
zerolinelayer="above traces" # Change to "below traces" to see the difference
647+
),
648+
)
649+
)
650+
651+
fig.show()
652+
```
653+
622654
#### Setting the Range of Axes Manually
623655

624656
The visible x and y axis range can be configured manually by setting the `range` axis property to a list of two values, the lower and upper bound.

doc/python/choropleth-maps.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,16 @@ fig.show()
208208
Plotly comes with two built-in geometries which do not require an external GeoJSON file:
209209

210210
1. USA States
211-
2. Countries as defined in the Natural Earth dataset.
211+
2. Countries
212212

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.
214216

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/).
216218

217219
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).
218220

219-
220221
```python
221222
import plotly.express as px
222223

doc/python/configuration-options.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
9-
jupytext_version: 1.4.2
8+
format_version: '1.3'
9+
jupytext_version: 1.17.2
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.12.4
2424
plotly:
2525
description: How to set the configuration options of figures using the Plotly
2626
Python graphing library.
@@ -323,6 +323,42 @@ fig.update_layout(xaxis={'type': 'date'})
323323
fig.show(config=config)
324324
```
325325

326+
### Disabling Buttons for Specific Axes
327+
328+
*New in 6.3*
329+
330+
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+
326362
### Configuring Figures in Dash Apps
327363

328364
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).

doc/python/hover-text-and-formatting.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.16.1
9+
jupytext_version: 1.17.2
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.10.11
23+
version: 3.12.4
2424
plotly:
2525
description: How to use hover text and formatting in Python with Plotly.
2626
display_as: file_settings
@@ -83,6 +83,57 @@ fig.update_layout(hovermode="x unified")
8383
fig.show()
8484
```
8585

86+
#### Customize Title in Unified Hovermode
87+
88+
*New in 6.3*
89+
90+
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+
86137
#### Control hovermode with Dash
87138

88139
[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`.

doc/python/legend.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.16.1
9+
jupytext_version: 1.17.2
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.10.11
23+
version: 3.9.0
2424
plotly:
2525
description: How to configure and style the legend in Plotly with Python.
2626
display_as: file_settings
@@ -254,6 +254,46 @@ fig.update_layout(legend=dict(
254254
fig.show()
255255
```
256256

257+
#### Legend Max Height
258+
259+
*New in 6.3*
260+
261+
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
290+
title_text="Country"
291+
),
292+
)
293+
294+
fig.show()
295+
```
296+
257297
#### Styling Legends
258298

259299
Legends support many styling options.

doc/python/log-plot.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.13.7
9+
jupytext_version: 1.17.2
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.9.7
23+
version: 3.12.4
2424
plotly:
2525
description: How to make Log plots in Python with Plotly.
2626
display_as: scientific
@@ -80,6 +80,38 @@ fig.update_xaxes(minor=dict(ticks="inside", ticklen=6, showgrid=True))
8080
fig.show()
8181
```
8282

83+
#### Controlling Minor Log Labels
84+
85+
*New in 6.3*
86+
87+
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+
83115
### Logarithmic Axes with Graph Objects
84116

85117
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/).

doc/python/map-configuration.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ Geo maps are outline-based maps. If your figure is created with a `px.scatter_ge
5151

5252
### Physical Base Maps
5353

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:
5563

5664
```python
5765
import plotly.graph_objects as go
@@ -102,9 +110,9 @@ fig.show()
102110

103111
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.
104112

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.
106114

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/).
108116

109117
**To create a map with your own cultural features** please refer to our [choropleth documentation](/python/choropleth-maps/).
110118

0 commit comments

Comments
 (0)