Skip to content

Commit b215b37

Browse files
committed
Fixed small missing import and variable errors. Also added 'getting-started.md' to the ToC.
1 parent 9a40907 commit b215b37

13 files changed

+92
-8
lines changed

doc/python/creating-and-updating-figures.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ You can also add traces to a figure produced by a figure factory or Plotly Expre
239239

240240
```python
241241
import plotly.express as px
242+
import plotly.graph_objects as go
242243

243244
df = px.data.iris()
244245

@@ -371,6 +372,10 @@ fig.show()
371372
Note that the following `update_layout()` operations are equivalent:
372373

373374
```python
375+
import plotly.graph_objects as go
376+
377+
fig = go.Figure(data=go.Bar(x=[1, 2, 3], y=[1, 3, 2]))
378+
374379
fig.update_layout(title_text="update_layout() Syntax Example",
375380
title_font_size=30)
376381

doc/python/ecdf-plots.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ In `standard` mode (the default), the right-most point is at 1 (or the total cou
9696

9797
```python
9898
import plotly.express as px
99+
df = px.data.tips()
99100
fig = px.ecdf(df, x=[1,2,3,4], markers=True, ecdfmode="standard",
100101
title="ecdfmode='standard' (Y=fraction at or below X value, this the default)")
101102
fig.show()
@@ -105,6 +106,7 @@ In `reversed` mode, the right-most point is at 1 (or the total count/sum, depend
105106

106107
```python
107108
import plotly.express as px
109+
df = px.data.tips()
108110
fig = px.ecdf(df, x=[1,2,3,4], markers=True, ecdfmode="reversed",
109111
title="ecdfmode='reversed' (Y=fraction at or above X value)")
110112
fig.show()
@@ -114,6 +116,7 @@ In `complementary` mode, the right-most point is at 0 and no points are at 1 (or
114116

115117
```python
116118
import plotly.express as px
119+
df = px.data.tips()
117120
fig = px.ecdf(df, x=[1,2,3,4], markers=True, ecdfmode="complementary",
118121
title="ecdfmode='complementary' (Y=fraction above X value)")
119122
fig.show()

doc/python/figure-introspection.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ print(full_fig.data[0])
117117
We see that this is an instance of `go.Scatter` (as expected, given the input) and that it has an attribute we've maybe never heard of called `cliponaxis` which by default seems to be set to `True` in this case. Let's find out more about this attribute using the built-in Python `help()` function
118118

119119
```python
120+
import plotly.graph_objects as go
120121
help(go.Scatter.cliponaxis)
121122
```
122123

@@ -130,6 +131,7 @@ fig.show()
130131
We can use this technique (of making a figure, and querying Plotly.js for the "full" version of that figure, and then exploring the attributes that are automatically set for us) to learn more about the range of possibilities that the figure schema makes available. We can drill down into `layout` attributes also:
131132

132133
```python
134+
import plotly.graph_objects as go
133135
help(go.layout.XAxis.autorange)
134136
```
135137

doc/python/figurewidget.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,26 @@ f
5656
Add traces or update the layout and then watch the output above update in real time.
5757

5858
```python
59-
f.add_scatter(y=[2, 1, 4, 3]);
59+
import plotly.graph_objects as go
60+
f = go.FigureWidget()
61+
62+
f.add_scatter(y=[2, 1, 4, 3])
6063
```
6164

6265
```python
63-
f.add_bar(y=[1, 4, 3, 2]);
66+
import plotly.graph_objects as go
67+
f = go.FigureWidget()
68+
f.add_scatter(y=[2, 1, 4, 3])
69+
70+
f.add_bar(y=[1, 4, 3, 2])
6471
```
6572

6673
```python
74+
import plotly.graph_objects as go
75+
f = go.FigureWidget()
76+
f.add_scatter(y=[2, 1, 4, 3])
77+
f.add_bar(y=[1, 4, 3, 2])
78+
6779
f.layout.title = 'Hello FigureWidget'
6880
```
6981

@@ -73,18 +85,42 @@ f.layout.title = 'Hello FigureWidget'
7385
#### Update the Data and the Layout
7486

7587
```python
88+
import plotly.graph_objects as go
89+
f = go.FigureWidget()
90+
f.add_scatter(y=[2, 1, 4, 3])
91+
f.add_bar(y=[1, 4, 3, 2])
92+
f.layout.title = 'Hello FigureWidget'
93+
7694
# update scatter data
7795
scatter = f.data[0]
7896
scatter.y = [3, 1, 4, 3]
7997
```
8098

8199
```python
100+
import plotly.graph_objects as go
101+
f = go.FigureWidget()
102+
f.add_scatter(y=[2, 1, 4, 3])
103+
f.add_bar(y=[1, 4, 3, 2])
104+
f.layout.title = 'Hello FigureWidget'
105+
scatter = f.data[0]
106+
scatter.y = [3, 1, 4, 3]
107+
82108
# update bar data
83109
bar = f.data[1]
84110
bar.y = [5, 3, 2, 8]
85111
```
86112

87113
```python
114+
import plotly.graph_objects as go
115+
f = go.FigureWidget()
116+
f.add_scatter(y=[2, 1, 4, 3])
117+
f.add_bar(y=[1, 4, 3, 2])
118+
f.layout.title = 'Hello FigureWidget'
119+
scatter = f.data[0]
120+
scatter.y = [3, 1, 4, 3]
121+
bar = f.data[1]
122+
bar.y = [5, 3, 2, 8]
123+
88124
f.layout.title.text = 'This is a new title'
89125
```
90126

@@ -114,5 +150,7 @@ f2
114150
See [these Jupyter notebooks](https://github.com/jonmmease/plotly_ipywidget_notebooks) for even more FigureWidget examples.
115151

116152
```python
153+
import plotly.graph_objects as go
154+
117155
help(go.FigureWidget)
118156
```

doc/python/imshow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ These two modes can be used for single- and multichannel data. The default value
239239

240240
```python
241241
import plotly.express as px
242+
import numpy as np
242243
img = np.arange(100, dtype=np.uint8).reshape((10, 10))
243244
fig = px.imshow(img, contrast_rescaling='infer')
244245
fig.show()

doc/python/ml-tsne-umap-projections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Just like t-SNE, [UMAP](https://umap-learn.readthedocs.io/en/latest/index.html)
110110
In the example below, we see how easy it is to use UMAP as a drop-in replacement for scikit-learn's `manifold.TSNE`.
111111

112112
```python
113-
from umap import UMAP
113+
from umap.umap_ import UMAP
114114
import plotly.express as px
115115

116116
df = px.data.iris()
@@ -146,7 +146,7 @@ Although there's over 1000 data points, and many more dimensions than the previo
146146
```python
147147
import plotly.express as px
148148
from sklearn.datasets import load_digits
149-
from umap import UMAP
149+
from umap.umap_ import UMAP
150150

151151
digits = load_digits()
152152

doc/python/network-graphs.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ G = nx.random_geometric_graph(200, 0.125)
5757
Add edges as disconnected lines in a single trace and nodes as a scatter trace
5858

5959
```python
60+
import plotly.graph_objects as go
61+
import networkx as nx
62+
63+
G = nx.random_geometric_graph(200, 0.125)
6064
edge_x = []
6165
edge_y = []
66+
6267
for edge in G.edges():
6368
x0, y0 = G.nodes[edge[0]]['pos']
6469
x1, y1 = G.nodes[edge[1]]['pos']
@@ -115,8 +120,12 @@ Another option would be to size points by the number of connections
115120
i.e. ```node_trace.marker.size = node_adjacencies```
116121

117122
```python
123+
import networkx as nx
124+
125+
G = nx.random_geometric_graph(200, 0.125)
118126
node_adjacencies = []
119127
node_text = []
128+
120129
for node, adjacencies in enumerate(G.adjacency()):
121130
node_adjacencies.append(len(adjacencies[1]))
122131
node_text.append('# of connections: '+str(len(adjacencies[1])))

doc/python/px-arguments.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ df.head()
5555
By default `px.data` functions return a pandas `DataFrame` object, but you can specify an alternative dataframe type using `return_type`. `pandas`, `polars`, `pyarrow`, `modin`, and `cuDF` are supported return types.
5656

5757
```python
58+
import plotly.express as px
59+
5860
df = px.data.iris(return_type='polars')
5961
df.head()
6062
```

doc/python/static-image-export.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,23 @@ Here's the bytes object displayed using `IPython.display.Image`:
204204

205205
```python
206206
from IPython.display import Image
207+
import plotly.express as px
208+
data_canada = px.data.gapminder().query("country == 'Canada'")
209+
fig = px.bar(data_canada, x='year', y='pop')
210+
img_bytes = fig.to_image(format="png")
211+
207212
Image(img_bytes)
208213
```
209214

210215
## Specify Image Dimensions and Scale
211216
In addition to the image format, the `to_image` and `write_image` functions provide arguments to specify the image `width` and `height` in logical pixels. They also provide a `scale` parameter that can be used to increase (`scale` > 1) or decrease (`scale` < 1) the physical resolution of the resulting image.
212217

213218
```python
219+
from IPython.display import Image
220+
import plotly.express as px
221+
data_canada = px.data.gapminder().query("country == 'Canada'")
222+
fig = px.bar(data_canada, x='year', y='pop')
223+
214224
img_bytes = fig.to_image(format="png", width=600, height=350, scale=2)
215225
Image(img_bytes)
216226
```

doc/python/ternary-contour.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ fig.show()
128128
Two modes are available in order to interpolate between data points: interpolation in Cartesian space (`interp_mode='cartesian'`) or interpolation using the [isometric log-ratio transformation](https://link.springer.com/article/10.1023/A:1023818214614) (see also [preprint](https://www.researchgate.net/profile/Leon_Parent2/post/What_is_the_best_approach_for_diagnosing_nutrient_disorders_and_formulating_fertilizer_recommendations/attachment/59d62a69c49f478072e9cf3f/AS%3A272541220835360%401441990298625/download/Egozcue+et+al+2003.pdf)), `interp_mode='ilr'`. The `ilr` transformation preserves metrics in the [simplex](https://en.wikipedia.org/wiki/Simplex) but is not defined on its edges.
129129

130130
```python
131+
import numpy as np
132+
import plotly.figure_factory as ff
133+
131134
a, b = np.mgrid[0:1:20j, 0:1:20j]
132135
mask = a + b <= 1
133136
a, b = a[mask], b[mask]
@@ -138,6 +141,9 @@ fig.show()
138141
```
139142

140143
```python
144+
import numpy as np
145+
import plotly.figure_factory as ff
146+
141147
a, b = np.mgrid[0:1:20j, 0:1:20j]
142148
mask = a + b <= 1
143149
a, b = a[mask], b[mask]

0 commit comments

Comments
 (0)