Skip to content

Commit 4c722f2

Browse files
authored
Merge pull request #4569 from plotly/docs-updates-5-21
Update plotly.js version to 2.31.0 + add docs
2 parents b909d48 + c39209a commit 4c722f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1631
-86
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ jobs:
447447
resource_class: xlarge
448448
docker:
449449
# specify the version you desire here
450-
# use `-browsers` prefix for selenium tests, for example, `3.6.1-browsers`
450+
# use `-browsers` prefix for selenium tests, for example, `3.9-browsers`
451451
- image: cimg/python:3.9-browsers
452452

453453
steps:

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## Unreleased
6+
7+
### Updated
8+
- Updated Plotly.js from version 2.30.0 to version 2.31.1. See the [plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md#2311----2024-04-15) for more information. These changes are reflected in the auto-generated `plotly.graph_objects` module. Notable changes include:
9+
- Add `zorder` attribute to various cartesian traces for controlling stacking order of SVG traces drawn into a subplot [[#6918](https://github.com/plotly/plotly.js/pull/6918), [#6953](https://github.com/plotly/plotly.js/pull/6953)],
10+
This feature was anonymously sponsored: thank you to our sponsor!
11+
- Add "between" option to shape layer for placing them above grid lines and below traces [[#6927](https://github.com/plotly/plotly.js/pull/6927)],
12+
with thanks to @my-tien for the contribution!
13+
- Add "raw" `sizemode` to cone trace [[#6938](https://github.com/plotly/plotly.js/pull/6938)]
14+
- Add `layout.hoversubplots` to enable hover effects across multiple cartesian suplots sharing one axis [[#6947](https://github.com/plotly/plotly.js/pull/6947), [#6950](https://github.com/plotly/plotly.js/pull/6950)]
15+
516
## [5.20.0] - 2024-03-13
617

718
### Updated

doc/python/cone-plot.md

+43-5
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.3.0
8+
format_version: '1.3'
9+
jupytext_version: 1.16.1
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.3
23+
version: 3.10.11
2424
plotly:
2525
description: How to make 3D Cone plots in Python with Plotly.
2626
display_as: 3d_charts
@@ -126,5 +126,43 @@ fig.update_layout(scene=dict(aspectratio=dict(x=1, y=1, z=0.8),
126126
fig.show()
127127
```
128128

129+
### Sizemode
130+
131+
Earlier examples use `sizemode="absolute"` when adjusting the cone size scaling with `sizeref`. `sizemode` also supports `raw`(new in 5.21) and `scaled`.
132+
133+
```python
134+
import plotly.graph_objects as go
135+
import pandas as pd
136+
137+
df = pd.read_csv(
138+
"https://raw.githubusercontent.com/plotly/datasets/master/cone_plot_data.csv"
139+
)
140+
141+
fig = go.Figure(
142+
data=go.Cone(
143+
x=df["x"],
144+
y=df["y"],
145+
z=df["z"],
146+
u=df["u"],
147+
v=df["v"],
148+
w=df["w"],
149+
sizemode="raw",
150+
sizeref=0.1,
151+
colorscale="Portland",
152+
cmin=0,
153+
cmax=80,
154+
hoverinfo="u+v+w+text",
155+
text="-> wind <-",
156+
),
157+
layout=dict(
158+
width=900, height=600, scene=dict(camera=dict(eye=dict(x=1.2, y=0, z=0.6)))
159+
),
160+
)
161+
162+
163+
fig.show()
164+
165+
```
166+
129167
#### Reference
130-
See https://plotly.com/python/reference/ for more information and chart attribute options!
168+
See https://plotly.com/python/reference/ for more information and chart attribute options!

doc/python/graphing-multiple-chart-types.md

+38-2
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.14.1
9+
jupytext_version: 1.16.1
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.8.0
23+
version: 3.10.11
2424
plotly:
2525
description: How to design figures with multiple chart types in python.
2626
display_as: file_settings
@@ -208,5 +208,41 @@ fig.add_trace(
208208
fig.show()
209209
```
210210

211+
#### Trace Zorder
212+
213+
*New in 5.21*
214+
215+
You can move a trace in front of or behind another trace by setting its `zorder`. All traces have a default `zorder` of `0`. In the following example, we set `zorder` on the bar trace to `1` to move it in front of the scatter trace.
216+
217+
```python
218+
import plotly.graph_objects as go
219+
220+
x = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
221+
y_bar = [10, 15, 7, 10, 17, 15, 14, 20, 16, 19, 15, 17]
222+
y_area = [12, 13, 10, 14, 15, 13, 16, 18, 15, 17, 14, 16]
223+
224+
area_trace = go.Scatter(
225+
x=x,
226+
y=y_area,
227+
fill="tozeroy",
228+
mode="lines+markers",
229+
name="Area Trace with default `zorder` of 0",
230+
line=dict(color="lightsteelblue"),
231+
)
232+
233+
bar_trace = go.Bar(
234+
x=x,
235+
y=y_bar,
236+
name="Bar Trace with `zorder` of 1",
237+
zorder=1,
238+
marker=dict(color="lightslategray"),
239+
)
240+
241+
fig = go.Figure(data=[area_trace, bar_trace])
242+
243+
fig.show()
244+
245+
```
246+
211247
#### Reference
212248
See https://plotly.com/python/reference/ for more information and attribute options!

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

+34-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.16.1
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.8.8
23+
version: 3.10.11
2424
plotly:
2525
description: How to use hover text and formatting in Python with Plotly.
2626
display_as: file_settings
@@ -116,6 +116,37 @@ fig.update_layout(hovermode='x unified')
116116
fig.show()
117117
```
118118

119+
#### Hover on Subplots
120+
121+
*New in 5.21*
122+
123+
Use `hoversubplots` to define how hover effects expand to additional subplots. With `hoversubplots=axis`, hover effects are included on stacked subplots using the same axis when `hovermode` is set to `x`, `x unified`, `y`, or `y unified`.
124+
125+
```python
126+
import plotly.graph_objects as go
127+
import pandas as pd
128+
from plotly import data
129+
130+
df = data.stocks()
131+
132+
layout = dict(
133+
hoversubplots="axis",
134+
title="Stock Price Changes",
135+
hovermode="x",
136+
grid=dict(rows=3, columns=1),
137+
)
138+
139+
data = [
140+
go.Scatter(x=df["date"], y=df["AAPL"], xaxis="x", yaxis="y", name="Apple"),
141+
go.Scatter(x=df["date"], y=df["GOOG"], xaxis="x", yaxis="y2", name="Google"),
142+
go.Scatter(x=df["date"], y=df["AMZN"], xaxis="x", yaxis="y3", name="Amazon"),
143+
]
144+
145+
fig = go.Figure(data=data, layout=layout)
146+
147+
fig.show()
148+
```
149+
119150
### Customizing Hover Label Appearance
120151

121152
Hover label text and colors default to trace colors in hover modes other than `unified`, and can be globally set via the `layout.hoverlabel` attributes. Hover label appearance can also be controlled per trace in `<trace>.hoverlabel`.

doc/python/line-and-scatter.md

+44-2
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.14.1
9+
jupytext_version: 1.16.1
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.8.0
23+
version: 3.10.11
2424
plotly:
2525
description: How to make scatter plots in Python with Plotly.
2626
display_as: basic
@@ -426,6 +426,48 @@ fig = go.Figure(data=go.Scatter(
426426
fig.show()
427427
```
428428

429+
#### Trace Zorder
430+
431+
*New in 5.21*
432+
433+
For many trace types, including `go.Scatter`, you can define the order traces are drawn in by setting a `zorder`. Traces with a higher `zorder` appear at the front, with traces with a lower `zorder` at the back. In this example, we give our trace for 'France' the highest `zorder`, meaning it is drawn in front of the other two traces:
434+
435+
```python
436+
import plotly.graph_objects as go
437+
import plotly.data as data
438+
439+
df = data.gapminder()
440+
441+
df_europe = df[df['continent'] == 'Europe']
442+
443+
trace1 = go.Scatter(x=df_europe[df_europe['country'] == 'France']['year'],
444+
y=df_europe[df_europe['country'] == 'France']['lifeExp'],
445+
mode='lines+markers',
446+
zorder=3,
447+
name='France',
448+
marker=dict(size=15))
449+
450+
trace2 = go.Scatter(x=df_europe[df_europe['country'] == 'Germany']['year'],
451+
y=df_europe[df_europe['country'] == 'Germany']['lifeExp'],
452+
mode='lines+markers',
453+
zorder=1,
454+
name='Germany',
455+
marker=dict(size=15))
456+
457+
trace3 = go.Scatter(x=df_europe[df_europe['country'] == 'Spain']['year'],
458+
y=df_europe[df_europe['country'] == 'Spain']['lifeExp'],
459+
mode='lines+markers',
460+
zorder=2,
461+
name='Spain',
462+
marker=dict(size=15))
463+
464+
layout = go.Layout(title='Life Expectancy in Europe Over Time')
465+
466+
fig = go.Figure(data=[trace1, trace2, trace3], layout=layout)
467+
468+
fig.show()
469+
```
470+
429471
#### Large Data Sets
430472

431473
Now in Plotly you can implement WebGL with `Scattergl()` in place of `Scatter()` <br>

doc/python/shapes.md

+55-2
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.14.6
9+
jupytext_version: 1.16.1
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.10
23+
version: 3.10.11
2424
plotly:
2525
description: How to make SVG shapes in python. Examples of lines, circle, rectangle,
2626
and path.
@@ -1105,5 +1105,58 @@ fig.show(
11051105
)
11061106
```
11071107

1108+
#### Shape Layer
1109+
1110+
By default, shapes are drawn above traces. You can also configure them to be drawn between traces and gridlines with `layer="between"` (new in 5.21), or below gridlines with `layer="below"`.
1111+
1112+
```python
1113+
import plotly.express as px
1114+
1115+
df = px.data.stocks(indexed=True)
1116+
1117+
fig = px.line(df)
1118+
1119+
fig.add_shape(
1120+
type="rect",
1121+
x0="2018-03-01",
1122+
y0=0,
1123+
x1="2018-08-01",
1124+
y1=3,
1125+
line_width=0,
1126+
layer="above",
1127+
label=dict(text="Above", textposition="top center", font=dict(size=15)),
1128+
fillcolor="LightGreen",
1129+
opacity=0.80,
1130+
)
1131+
1132+
fig.add_shape(
1133+
type="rect",
1134+
x0="2018-10-01",
1135+
y0=0,
1136+
x1="2019-03-01",
1137+
y1=3,
1138+
line_width=0,
1139+
layer="between",
1140+
label=dict(text="Between", textposition="top center", font=dict(size=15)),
1141+
fillcolor="LightGreen",
1142+
opacity=0.80,
1143+
)
1144+
1145+
fig.add_shape(
1146+
type="rect",
1147+
x0="2019-05-01",
1148+
y0=0,
1149+
x1="2019-10-01",
1150+
y1=3,
1151+
line_width=0,
1152+
layer="below",
1153+
label=dict(text="Below", textposition="top center", font=dict(size=15)),
1154+
fillcolor="LightGreen",
1155+
opacity=0.80,
1156+
)
1157+
1158+
fig.show()
1159+
```
1160+
11081161
### Reference
11091162
See https://plotly.com/python/reference/layout/shapes/ for more information and chart attribute options!

0 commit comments

Comments
 (0)