Skip to content

Commit 49c4c02

Browse files
authored
Merge pull request #4165 from plotly/update-plotlyjs-docs
Update plotlyjs version to 2.22.0 and update docs
2 parents 59ffd90 + 981bef4 commit 49c4c02

File tree

1,168 files changed

+5615
-1624
lines changed

Some content is hidden

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

1,168 files changed

+5615
-1624
lines changed

doc/python/legend.md

Lines changed: 66 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.14.1
9+
jupytext_version: 1.14.5
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.8.8
2424
plotly:
2525
description: How to configure and style the legend in Plotly with Python.
2626
display_as: file_settings
@@ -574,6 +574,70 @@ fig.update_layout(width=600, title_text='Exploration of a vector field using sev
574574
fig.show()
575575
```
576576

577+
### Adding Multiple Legends
578+
579+
*New in 5.15*
580+
581+
By default, all traces appear on one legend. To have multiple legends, specify an alternative legend for a trace using the `legend` property. For a second legend, set `legend="legend2"`. Specify more legends with `legend="legend3"`, `legend="legend4"` and so on.
582+
583+
In this example, the last two scatter traces display on the second legend, "legend2". On the figure's layout, we then position and style this legend to display on the right of the graph below the first legend.
584+
585+
586+
```python
587+
import plotly.graph_objects as go
588+
from plotly import data
589+
590+
df = data.gapminder()
591+
592+
df_germany = df.loc[(df.country.isin(["Germany"]))]
593+
df_france = df.loc[(df.country.isin(["France"]))]
594+
df_uk = df.loc[(df.country.isin(["United Kingdom"]))]
595+
596+
597+
df_averages_europe = (
598+
df.loc[(df.continent.isin(["Europe"]))].groupby(by="year").mean(numeric_only=True)
599+
)
600+
df_averages_americas = (
601+
df.loc[(df.continent.isin(["Americas"]))].groupby(by="year").mean(numeric_only=True)
602+
)
603+
604+
605+
fig = go.Figure(
606+
data=[
607+
go.Scatter(x=df_germany.year, y=df_germany.gdpPercap, name="Germany"),
608+
go.Scatter(x=df_france.year, y=df_france.gdpPercap, name="France"),
609+
go.Scatter(x=df_uk.year, y=df_uk.gdpPercap, name="UK"),
610+
go.Scatter(
611+
x=df_averages_europe.index,
612+
y=df_averages_europe.gdpPercap,
613+
name="Europe",
614+
legend="legend2",
615+
),
616+
go.Scatter(
617+
x=df_averages_americas.index,
618+
y=df_averages_americas.gdpPercap,
619+
name="Americas",
620+
legend="legend2",
621+
),
622+
],
623+
layout=dict(
624+
title="GDP Per Capita",
625+
legend={"title": "By country", "bgcolor": "Orange",},
626+
legend2={
627+
"x": 1.155,
628+
"y": 0.55,
629+
"xanchor": "right",
630+
"yanchor": "middle",
631+
"bgcolor": "Gold",
632+
"title": {"text": "By continent"},
633+
},
634+
),
635+
)
636+
637+
fig.show()
638+
639+
```
640+
577641
#### Reference
578642

579643
See https://plotly.com/python/reference/layout/#layout-legend for more information!

doc/python/shapes.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.10.9
23+
version: 3.8.8
2424
plotly:
2525
description: How to make SVG shapes in python. Examples of lines, circle, rectangle,
2626
and path.
@@ -913,5 +913,91 @@ fig.add_shape(
913913
fig.show()
914914
```
915915

916+
#### Variables in Shape Label Text
917+
918+
*New in 5.15*
919+
920+
Use `texttemplate` to add text with variables to shapes. `texttemplate` uses d3 number and date formatting and supports raw variables, which use the raw data from the shape definition, and some calculated variables. Add a variable with "%{variable}".
921+
922+
This example adds the raw variables `x0` and `y0` to a rectangle and shows the calculated variables `height`, `slope`, and `width` on three other shapes.
923+
924+
For a complete list of available variables, see the [Shape Reference Docs](https://plotly.com/python/reference/layout/shapes/).
925+
926+
927+
```python
928+
import plotly.graph_objects as go
929+
930+
fig = go.Figure()
931+
932+
fig.add_shape(
933+
type="rect",
934+
fillcolor="MediumSlateBlue",
935+
x0=-0.5,
936+
y0=-0.5,
937+
x1=1,
938+
y1=1,
939+
label=dict(
940+
texttemplate="x0 is %{x0:.3f}, y0 is %{y0:.3f}", font=dict(color="DarkOrange")
941+
),
942+
)
943+
944+
fig.add_shape(
945+
type="rect",
946+
fillcolor="LightGreen",
947+
x0=1,
948+
y0=1.75,
949+
x1=2.25,
950+
y1=3,
951+
label=dict(texttemplate="Height: %{height:.3f}", font=dict(color="DarkOrange")),
952+
)
953+
fig.add_shape(
954+
type="line",
955+
x0=3,
956+
y0=0.5,
957+
x1=5,
958+
y1=0.8,
959+
line_width=3,
960+
label=dict(texttemplate="Slope: %{slope:.3f}", font=dict(size=20)),
961+
)
962+
fig.add_shape(
963+
type="rect",
964+
fillcolor="Lavender",
965+
x0=2.5,
966+
y0=2.5,
967+
x1=5,
968+
y1=3.5,
969+
label=dict(
970+
texttemplate="Width: %{width:.3f}",
971+
font=dict(family="Courier New, monospace", size=20),
972+
),
973+
)
974+
975+
fig.show()
976+
977+
```
978+
979+
#### Variables in Shape Label Text for New Shapes
980+
981+
*New in 5.15*
982+
983+
Use `texttemplate` to add text with variables to new shapes drawn on the graph. This example figure is configured to allow the user to draw lines and automatically labels each line with its slope. Select **Draw line** in the modebar to try it out.
984+
985+
```python
986+
import plotly.graph_objects as go
987+
988+
fig = go.Figure(
989+
layout=go.Layout(newshape=dict(label=dict(texttemplate="Slope: %{slope:.3f}")))
990+
)
991+
992+
fig.show(
993+
config={
994+
"modeBarButtonsToAdd": [
995+
"drawline",
996+
]
997+
}
998+
)
999+
1000+
```
1001+
9161002
### Reference
9171003
See https://plotly.com/python/reference/layout/shapes/ for more information and chart attribute options!

packages/javascript/jupyterlab-plotly/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/javascript/jupyterlab-plotly/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@lumino/messaging": "^1.2.3",
6666
"@lumino/widgets": "^1.8.1",
6767
"lodash": "^4.17.4",
68-
"plotly.js": "^2.20.0"
68+
"plotly.js": "^2.22.0"
6969
},
7070
"jupyterlab": {
7171
"extension": "lib/jupyterlab-plugin",

0 commit comments

Comments
 (0)