Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72bc7c8

Browse files
authored
Merge branch 'master' into patch-1
2 parents f6af929 + 42266b0 commit 72bc7c8

File tree

1,196 files changed

+7126
-2663
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,196 files changed

+7126
-2663
lines changed

.circleci/config.yml

Lines changed: 157 additions & 58 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ doc/check-or-enforce-order.py
5252
packages/javascript/jupyterlab-plotly/lib/
5353
packages/python/plotly/jupyterlab_plotly/labextension/
5454
packages/python/plotly/jupyterlab_plotly/nbextension/index.js*
55+
56+
test/percy/*.html
57+
test/percy/pandas2/*.html

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
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+
### Fixed
8+
- Fixed another compatibility issue with Pandas 2.0, just affecting `px.*(line_close=True)` [[#4190](https://github.com/plotly/plotly.py/pull/4190)]
9+
- Added some rounding to the `make_subplots` function to handle situations where the user-input specs cause the domain to exceed 1 by small amounts [[#4153](https://github.com/plotly/plotly.py/pull/4153)]
10+
- Sanitize JSON output to prevent an XSS vector when graphs are inserted directly into HTML [[#4196](https://github.com/plotly/plotly.py/pull/4196)]
11+
- Fixed issue with shapes and annotations plotting on the wrong y axis when supplied with a specific axis in the `yref` parameter [[#4177](https://github.com/plotly/plotly.py/pull/4177)]
12+
- Remove `use_2to3` setuptools arg, which is invalid in the latest Python and setuptools versions [[#4206](https://github.com/plotly/plotly.py/pull/4206)]
13+
- Fix [#4066](https://github.com/plotly/plotly.py/issues/4066) JupyterLab v4 giving tiny default graph height [[#4227](https://github.com/plotly/plotly.py/pull/4227)]
14+
515
## [5.14.1] - 2023-04-05
616

717
### Fixed
@@ -10,7 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1020
## [5.14.0] - 2023-03-29
1121

1222
### Updated
13-
- Updated Plotly.js to from version 2.18.2 to version 2.20.0. See the [plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md#2200----2023-03-15) for more information. Notable changes include:
23+
- Updated Plotly.js from version 2.18.2 to version 2.20.0. See the [plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md#2200----2023-03-15) for more information. Notable changes include:
1424
- Add `title.automargin` to enable automatic top and bottom margining for both container and paper referenced titles [[#6428](https://github.com/plotly/plotly.js/pull/6428)],
1525
with thanks to [Gamma Technologies](https://www.gtisoft.com/) for sponsoring the related development.
1626
- Add `label` attribute to shapes [[#6454](https://github.com/plotly/plotly.js/pull/6454)], with thanks to the [Volkswagen](https://www.volkswagenag.com) Center of Excellence for Battery Systems for sponsoring development!

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!

doc/python/static-image-export.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,42 +109,42 @@ If you are running this notebook live, click to [open the output directory](./im
109109

110110
plotly.py can output figures to several raster image formats including **PNG**, ...
111111

112-
```python
112+
~~~python
113113
fig.write_image("images/fig1.png")
114-
```
114+
~~~
115115

116116
**JPEG**, ...
117117

118-
```python
118+
~~~python
119119
fig.write_image("images/fig1.jpeg")
120-
```
120+
~~~
121121

122122
and **WebP**
123123

124-
```python
124+
~~~python
125125
fig.write_image("images/fig1.webp")
126-
```
126+
~~~
127127

128128
#### Vector Formats: SVG and PDF...
129129

130130

131131
plotly.py can also output figures in several vector formats including **SVG**, ...
132132

133-
```python
133+
~~~python
134134
fig.write_image("images/fig1.svg")
135-
```
135+
~~~
136136

137137
**PDF**, ...
138138

139-
```python
139+
~~~python
140140
fig.write_image("images/fig1.pdf")
141-
```
141+
~~~
142142

143143
and **EPS** (requires the poppler library)
144144

145-
```python
145+
~~~python
146146
fig.write_image("images/fig1.eps")
147-
```
147+
~~~
148148

149149
**Note:** It is important to note that any figures containing WebGL traces (i.e. of type `scattergl`, `heatmapgl`, `contourgl`, `scatter3d`, `surface`, `mesh3d`, `scatterpolargl`, `cone`, `streamtube`, `splom`, or `parcoords`) that are exported in a vector format will include encapsulated rasters, instead of vectors, for some parts of the image.
150150

@@ -199,14 +199,14 @@ Image(img_bytes)
199199
If `kaleido` is installed, it will automatically be used to perform image export. If it is not installed, plotly.py will attempt to use `orca` instead. The `engine` argument to the `to_image` and `write_image` functions can be used to override this default behavior.
200200

201201
Here is an example of specifying that orca should be used:
202-
```python
202+
~~~python
203203
fig.to_image(format="png", engine="orca")
204-
```
204+
~~~
205205

206206
And, here is an example of specifying that Kaleido should be used:
207-
```python
207+
~~~python
208208
fig.to_image(format="png", engine="kaleido")
209-
```
209+
~~~
210210

211211
<!-- #endregion -->
212212

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",

packages/javascript/jupyterlab-plotly/src/Figure.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,9 @@ export class FigureView extends DOMWidgetView {
849849
// the model is not directly mutated by the Plotly.js library.
850850
var initialTraces = _.cloneDeep(this.model.get("_data"));
851851
var initialLayout = _.cloneDeep(this.model.get("_layout"));
852+
if (!initialLayout.height) {
853+
initialLayout.height = 360;
854+
}
852855
var config = this.model.get("_config");
853856
config.editSelection = false;
854857

packages/javascript/jupyterlab-plotly/src/plotly-renderer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,16 @@ export class RenderedPlotly extends Widget implements IRenderMime.IRenderer {
126126
| any
127127
| IPlotlySpec;
128128

129+
if (!layout.height) {
130+
layout.height = 360;
131+
}
132+
129133
// Load plotly asynchronously
130134
const loadPlotly = async (): Promise<void> => {
131135
if (RenderedPlotly.Plotly === null) {
132136
RenderedPlotly.Plotly = await import("plotly.js/dist/plotly");
133137
RenderedPlotly._resolveLoadingPlotly();
134-
}
138+
}
135139
return RenderedPlotly.loadingPlotly;
136140
};
137141

packages/javascript/jupyterlab-plotly/style/index.css

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
overflow: hidden;
2222
}
2323

24-
/* Output styles */
25-
.jp-OutputArea .jp-RenderedPlotly {
26-
min-height: 360px;
27-
}
28-
2924
/* Document icon */
3025
.jp-PlotlyIcon {
3126
background-image: var(--jp-icon-plotly);
32-
}
27+
}

0 commit comments

Comments
 (0)