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

Skip to content

Commit a439aff

Browse files
committed
Review and updates to migration guide
1 parent 69339e2 commit a439aff

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed

example_images/simple_scatter.png

14.5 KB
Loading

example_images/subplot_methods.png

52.2 KB
Loading

migration-guide.md

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Migration to Plotly 3.0.0
1+
# Migration to Version 3
22
There are many new and great features in Plotly 3.0 including deeper Jupyter integration, deeper figure validation, improved performance, and more. To get started right away with Plotly, check out the tutorial below:
33

44
## Simple FigureWidget Example
5-
We now have a seamless integration of Jupyter support and the Plotly objects. We've introduced a new graph object called `go.FigureWidget` that acts like a regular plotly `go.Figure` that can be displayed in Jupyter.
5+
We now have seamless integration with the Jupyter widget ecosystem. We've introduced a new graph object called `go.FigureWidget` that acts like a regular plotly `go.Figure` that can be directly displayed in the notebook.
66

77
Simple Example: Make a Scatter Plot
8-
```
8+
```python
99
import plotly
1010
import plotly.graph_objs as go
1111

@@ -22,11 +22,15 @@ Entering `f.add_scatter(<tab>)` displays the names of all of the top-level prope
2222

2323
Entering `f.add_scatter(<shift+tab>)` displays the signature pop-up. Expanding this pop-up reveals the method doc string which contains the descriptions of all of the top level properties. Let's finish add a scatter trace to `f`:
2424

25-
```
26-
f.add_scatter(x=[1,2,3], y=[4,3,2])
25+
```python
26+
f.add_scatter(x=[1,2,3], y=[3,4,2])
2727
f
2828
```
2929

30+
![Simple Scatter](example_images/simple_scatter.png)
31+
32+
Notice that you don't need to use one of the legacy `iplot` methods to display a `FigureWidget`. Its visual representation is the plot itself!
33+
3034
## New Plotly Object Representation
3135
Plotly figures and graph objects have an updated `__repr__` method that displays objects in a pretty printed form that can be copied, pasted, and evaluated to recreate the object.
3236

@@ -39,27 +43,12 @@ FigureWidget({
3943
})
4044
```
4145

42-
## New Figure.data Assignment
43-
- Assignment to the `Figure.data` property must contain a permutation of a subset of the existing traces. Assignment can be used to reorder and remove traces, but cannot currently add new traces.
44-
45-
Suppose a figure, fig, has 3 traces. The following command is valid and it will move the third trace to be the first, the first trace to be the second, and it will remove the second trace.
46-
47-
```
48-
fig.data = [fig.data[2], fig.data[0]]
49-
```
50-
51-
However this is not valid:
52-
```
53-
fig.data = [fig.data[0], go.Scatter(y=[2, 3, 1])]
54-
```
55-
56-
It's not valid because it's introducing a new trace during assignment. This trace would need to be added using `add_trace` instead.
57-
46+
## New add_trace method that handles subplots
47+
The legacy `append_trace` method for adding traces to subplots has been deprecated in favor of the new `add_trace`, `add_traces`, and `add_*` methods. Each of these new methods accepts optional row/column information that may be used to add traces to subplots for figures initialized by the `plotly.tools.make_subplots` function.
5848

59-
## FigureWidget Subplot Example
60-
Let's create a subplot then turn it into a FigureWidget to display in the notebook. Note that `append_trace` is now deprecated. Use `add_trace` or `add_traces` instead.
49+
Let's create a subplot then turn it into a FigureWidget to display in the notebook.
6150

62-
```
51+
```python
6352
import plotly
6453
import plotly.graph_objs as go
6554
import plotly.tools as tls
@@ -70,27 +59,58 @@ dataset = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/
7059
subplot = tls.make_subplots(2, 2, print_grid=False)
7160
f2 = go.FigureWidget(subplot)
7261

73-
f2.add_trace(go.Scatter(x=dataset['Age'], y=dataset['Pregnancies'], mode='markers'), 1,1)
74-
f2.add_trace(go.Scatter(x=dataset['Age'], y=dataset['BMI'], mode='markers'), 1,2)
75-
f2.add_trace(go.Scatter(x=dataset['Age'], y=dataset['SkinThickness'], mode='markers'), 2,1)
76-
f2.add_trace(go.Scatter(x=dataset['Age'], y=dataset['BloodPressure'], mode='markers'), 2,2)
77-
f2.layout.title = 'Age against variables relating to diabetes'
62+
# Use add_trace method with optional row/col parameters
63+
f2.add_trace(go.Scatter(x=dataset['Age'], y=dataset['Pregnancies'], mode='markers'), row=1, col=1)
64+
65+
# Use add_traces with optional rows/cols parameters
66+
f2.add_traces([
67+
go.Scatter(x=dataset['Age'], y=dataset['BMI'], mode='markers'),
68+
go.Scatter(x=dataset['Age'], y=dataset['SkinThickness'], mode='markers')],
69+
rows=[1, 2], cols=[2, 1]
70+
)
71+
72+
# Use add_scatter with optional row/col parameters
73+
f2.add_scatter(x=dataset['Age'], y=dataset['BloodPressure'], mode='markers', row=2, col=2)
74+
75+
f2.layout.title = 'Age and Diabetes Factors'
7876
f2
7977
```
8078

79+
![Simple Subplots](example_images/subplot_methods.png)
80+
8181
## Breaking Changes
82-
Run the following examples to see what is now deprecated or not valid:
8382

84-
- Data array properties may not be specified as scalars:
83+
### Property Immutability
84+
In order to support the automatic synchronization a `FigureWidget` object and the front-end view in a notebook, it is necessary for the `FigureWidget` to be aware of all changes to its properties. This is accomplished by presenting the individual properties to the user as immutable objects. For example, the `layout.xaxis.range` property may be assigned using a list, but it will be returned as a tuple.
85+
86+
### New Figure.data Assignment
87+
There are new restriction on the assignment of traces to the `data` property of a figure. The assigned value must be a list or a tuple of a subset of the traces already present in the figure. Assignment to `data` may be used to reorder and remove existing traces, but it may not currently be used to add new traces. New traces must be added using the `add_trace`, `add_traces`, or `add_*` methods.
88+
89+
For example, suppose a figure, `fig`, has 3 traces. The following command is valid and it will move the third trace to be the first, the first trace to be the second, and it will remove the second trace.
90+
8591
```
86-
import plotly.graph_objs as go
87-
go.Bar(x=1)
92+
fig.data = [fig.data[2], fig.data[0]]
93+
```
94+
95+
However this is not valid:
96+
```
97+
fig.data = [fig.data[0], go.Scatter(y=[2, 3, 1])]
8898
```
8999

90-
- Several undocumented `Figure` methods have been removed. These include: `.to_string`, `.strip_style`, `.get_data`, `.validate` and `.to_dataframe`.
100+
It's not valid because it's introducing a new trace during assignment. This trace would need to be added using `add_trace` instead.
91101

92-
- Object arrays such as `Figure.data` and `Layout.images` are now represented as tuples of graph objects, not lists. Run the following as a sanity check:
102+
### Data array properties may not be specified as scalars
103+
For example, the following is now invalid:
104+
```
105+
import plotly.graph_objs as go
106+
go.Bar(x=1)
107+
```
93108

109+
This should be replaced by:
94110
```
95-
type(go.Figure().data)
111+
import plotly.graph_objs as go
112+
go.Bar(x=[1])
96113
```
114+
115+
### Removal of undocumented methods
116+
Several undocumented `Figure` methods have been removed. These include: `.to_string`, `.strip_style`, `.get_data`, `.validate` and `.to_dataframe`.

0 commit comments

Comments
 (0)