Skip to content

Commit e778e0b

Browse files
committed
graph_objects, update_layout
1 parent 4082a8c commit e778e0b

9 files changed

+110
-103
lines changed

notebooks/box-plots.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ fig.show()
8888

8989
## Box plot with go.Box
9090

91-
When data are not available as tidy dataframes, it is also possible to use the more generic `go.Box` function from `plotly.graph_objs`. All available options for `go.Box` are described in the reference page https://plot.ly/python/reference/#box.
91+
When data are not available as tidy dataframes, it is also possible to use the more generic `go.Box` function from `plotly.graph_objects`. All available options for `go.Box` are described in the reference page https://plot.ly/python/reference/#box.
9292

9393
### Basic Box Plot ###
9494

9595
```python
96-
import plotly.graph_objs as go
96+
import plotly.graph_objects as go
9797
import numpy as np
9898

9999
y0 = np.random.randn(50) - 1
@@ -109,7 +109,7 @@ fig.show()
109109
### Basic Horizontal Box Plot ###
110110

111111
```python
112-
import plotly.graph_objs as go
112+
import plotly.graph_objects as go
113113
import numpy as np
114114

115115
x0 = np.random.randn(50)
@@ -126,7 +126,7 @@ fig.show()
126126
### Box Plot That Displays the Underlying Data ###
127127

128128
```python
129-
import plotly.graph_objs as go
129+
import plotly.graph_objects as go
130130

131131
fig = go.Figure(data=[go.Box(y=[0, 1, 1, 2, 3, 5, 8, 13, 21],
132132
boxpoints='all', # can also be outliers, or suspectedoutliers, or False
@@ -140,7 +140,7 @@ fig.show()
140140
### Colored Box Plot ###
141141

142142
```python
143-
import plotly.graph_objs as go
143+
import plotly.graph_objects as go
144144
import numpy as np
145145

146146
y0 = np.random.randn(50)
@@ -158,7 +158,7 @@ fig.show()
158158
### Box Plot Styling Mean & Standard Deviation ###
159159

160160
```python
161-
import plotly.graph_objs as go
161+
import plotly.graph_objects as go
162162

163163
fig = go.Figure()
164164
fig.add_trace(go.Box(
@@ -182,7 +182,7 @@ fig.show()
182182
The example below shows how to use the `boxpoints` argument. If "outliers", only the sample points lying outside the whiskers are shown. If "suspectedoutliers", the outlier points are shown and points either less than 4Q1-3Q3 or greater than 4Q3-3Q1 are highlighted (using `outliercolor`). If "all", all sample points are shown. If False, only the boxes are shown with no sample points.
183183

184184
```python
185-
import plotly.graph_objs as go
185+
import plotly.graph_objects as go
186186

187187
fig = go.Figure()
188188
fig.add_trace(go.Box(
@@ -229,13 +229,14 @@ fig.add_trace(go.Box(
229229
))
230230

231231

232-
fig.update(layout_title_text="Box Plot Styling Outliers")
232+
fig.update_layout(title_text="Box Plot Styling Outliers")
233+
fig.show()
233234
```
234235

235236
### Grouped Box Plots ###
236237

237238
```python
238-
import plotly.graph_objs as go
239+
import plotly.graph_objects as go
239240

240241
x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1',
241242
'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']
@@ -261,17 +262,17 @@ fig.add_trace(go.Box(
261262
marker_color='#FF851B'
262263
))
263264

264-
fig.update(layout = go.Layout(
265+
fig.update_layout(
265266
yaxis_title='normalized moisture',
266267
boxmode='group' # group together boxes of the different traces for each value of x
267-
))
268-
268+
)
269+
fig.show()
269270
```
270271

271272
### Grouped Horizontal Box Plot ###
272273

273274
```python
274-
import plotly.graph_objs as go
275+
import plotly.graph_objects as go
275276

276277
y = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1',
277278
'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']
@@ -296,21 +297,19 @@ fig.add_trace(go.Box(
296297
marker_color='#FF851B'
297298
))
298299

299-
fig.update(layout = go.Layout(
300-
xaxis=dict(
301-
title='normalized moisture',
302-
zeroline=False
303-
),
300+
fig.update_layout(
301+
xaxis=dict(title='normalized moisture', zeroline=False),
304302
boxmode='group'
305-
))
303+
)
306304

307305
fig.update_traces(orientation='h') # horizontal box plots
306+
fig.show()
308307
```
309308

310309
### Rainbow Box Plots ###
311310

312311
```python
313-
import plotly.graph_objs as go
312+
import plotly.graph_objects as go
314313
import numpy as np
315314

316315
N = 30 # Number of boxes
@@ -328,12 +327,12 @@ fig = go.Figure(data=[go.Box(
328327
) for i in range(int(N))])
329328

330329
# format the layout
331-
fig.update(layout = go.Layout(
330+
fig.update_layout(
332331
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
333332
yaxis=dict(zeroline=False, gridcolor='white'),
334333
paper_bgcolor='rgb(233,233,233)',
335334
plot_bgcolor='rgb(233,233,233)',
336-
))
335+
)
337336

338337
fig.show()
339338
```
@@ -342,7 +341,7 @@ fig.show()
342341

343342

344343
```python
345-
import plotly.graph_objs as go
344+
import plotly.graph_objects as go
346345

347346
x_data = ['Carmelo Anthony', 'Dwyane Wade',
348347
'Deron Williams', 'Brook Lopez',
@@ -376,7 +375,7 @@ for xd, yd, cls in zip(x_data, y_data, colors):
376375
line_width=1)
377376
)
378377

379-
fig.update(layout = go.Layout(
378+
fig.update_layout(
380379
title='Points Scored by the Top 9 Scoring NBA Players in 2012',
381380
yaxis=dict(
382381
autorange=True,
@@ -397,7 +396,7 @@ fig.update(layout = go.Layout(
397396
paper_bgcolor='rgb(243, 243, 243)',
398397
plot_bgcolor='rgb(243, 243, 243)',
399398
showlegend=False
400-
))
399+
)
401400

402401
fig.show()
403402
```

notebooks/bubble-charts.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,20 @@ We first show a bubble chart example using plotly express. Plotly express functi
4848
import plotly.express as px
4949
gapminder = px.data.gapminder()
5050

51-
px.scatter(gapminder.query("year==2007"), x="gdpPercap", y="lifeExp",
52-
size="pop", color="continent",
53-
hover_name="country", log_x=True, size_max=60)
51+
fig = px.scatter(gapminder.query("year==2007"), x="gdpPercap", y="lifeExp",
52+
size="pop", color="continent",
53+
hover_name="country", log_x=True, size_max=60)
54+
fig.show()
5455
```
5556

56-
## Bubble Chart with plotly.graph_objs
57+
## Bubble Chart with plotly.graph_objects
5758

58-
When data are not available as tidy dataframes, it is also possible to use the more generic `go.Scatter` from `plotly.graph_objs`, and define the size of markers to create a bubble chart. All of the available options are described in the scatter section of the reference page: https://plot.ly/python/reference#scatter.
59+
When data are not available as tidy dataframes, it is also possible to use the more generic `go.Scatter` from `plotly.graph_objects`, and define the size of markers to create a bubble chart. All of the available options are described in the scatter section of the reference page: https://plot.ly/python/reference#scatter.
5960

6061
### Simple Bubble Chart
6162

6263
```python
63-
import plotly.graph_objs as go
64+
import plotly.graph_objects as go
6465

6566
fig = go.Figure(data=[go.Scatter(
6667
x=[1, 2, 3, 4], y=[10, 11, 12, 13],
@@ -74,7 +75,7 @@ fig.show()
7475
### Setting Marker Size and Color
7576

7677
```python
77-
import plotly.graph_objs as go
78+
import plotly.graph_objects as go
7879

7980
fig = go.Figure(data=[go.Scatter(
8081
x=[1, 2, 3, 4], y=[10, 11, 12, 13],
@@ -97,7 +98,7 @@ Note that setting 'sizeref' to a value greater than 1, decreases the rendered ma
9798
Additionally, we recommend setting the sizemode attribute: https://plot.ly/python/reference/#scatter-marker-sizemode to area.
9899

99100
```python
100-
import plotly.graph_objs as go
101+
import plotly.graph_objects as go
101102

102103
size = [20, 40, 60, 80, 100, 80, 60, 40, 20, 40]
103104
fig = go.Figure(data=[go.Scatter(
@@ -118,7 +119,7 @@ fig.show()
118119
### Hover Text with Bubble Charts
119120

120121
```python
121-
import plotly.graph_objs as go
122+
import plotly.graph_objects as go
122123

123124
fig = go.Figure(data=[go.Scatter(
124125
x=[1, 2, 3, 4], y=[10, 11, 12, 13],
@@ -136,7 +137,7 @@ fig.show()
136137
### Bubble Charts with Colorscale
137138

138139
```python
139-
import plotly.graph_objs as go
140+
import plotly.graph_objects as go
140141

141142
fig = go.Figure(data=[go.Scatter(
142143
x=[1, 3.2, 5.4, 7.6, 9.8, 12.5],
@@ -155,7 +156,7 @@ fig.show()
155156
### Categorical Bubble Charts
156157

157158
```python
158-
import plotly.graph_objs as go
159+
import plotly.graph_objects as go
159160
import plotly.express as px
160161
import pandas as pd
161162
import math
@@ -203,7 +204,7 @@ for continent_name, continent in continent_data.items():
203204
fig.update_traces(mode='markers', marker=dict(sizemode='area',
204205
sizeref=sizeref, line_width=2))
205206

206-
fig.update(layout=go.Layout(
207+
fig.update_layout(
207208
title='Life Expectancy v. Per Capita GDP, 2007',
208209
xaxis=dict(
209210
title='GDP per capita (2000 dollars)',
@@ -218,7 +219,8 @@ fig.update(layout=go.Layout(
218219
),
219220
paper_bgcolor='rgb(243, 243, 243)',
220221
plot_bgcolor='rgb(243, 243, 243)',
221-
))
222+
)
223+
fig.show()
222224
```
223225

224226
### Reference

notebooks/candlestick-charts.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ time). The boxes represent the spread between the `open` and `close` values and
4545
#### Simple Candlestick with Pandas
4646

4747
```python
48-
import plotly.graph_objs as go
48+
import plotly.graph_objects as go
4949

5050
import pandas as pd
5151
from datetime import datetime
@@ -64,7 +64,7 @@ fig.show()
6464
#### Candlestick without Rangeslider
6565

6666
```python
67-
import plotly.graph_objs as go
67+
import plotly.graph_objects as go
6868
import pandas as pd
6969

7070
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
@@ -74,13 +74,14 @@ fig = go.Figure(data=[go.Candlestick(x=df['Date'],
7474
low=df['AAPL.Low'], close=df['AAPL.Close'])
7575
])
7676

77-
fig.update(layout_xaxis_rangeslider_visible=False)
77+
fig.update_layout(xaxis_rangeslider_visible=False)
78+
fig.show()
7879
```
7980

8081
#### Adding Customized Text and Annotations
8182

8283
```python
83-
import plotly.graph_objs as go
84+
import plotly.graph_objects as go
8485
import pandas as pd
8586

8687

@@ -91,7 +92,7 @@ fig = go.Figure(data=[go.Candlestick(x=df['Date'],
9192
low=df['AAPL.Low'], close=df['AAPL.Close'])
9293
])
9394

94-
fig.update(layout=go.Layout(
95+
fig.update_layout(
9596
title='The Great Recession',
9697
yaxis_title='AAPL Stock',
9798
shapes = [dict(
@@ -100,15 +101,15 @@ fig.update(layout=go.Layout(
100101
annotations=[dict(
101102
x='2016-12-09', y=0.05, xref='x', yref='paper',
102103
showarrow=False, xanchor='left', text='Increase Period Begins')]
103-
))
104+
)
104105

105106
fig.show()
106107
```
107108

108109
#### Custom Candlestick Colors
109110

110111
```python
111-
import plotly.graph_objs as go
112+
import plotly.graph_objects as go
112113
import pandas as pd
113114

114115
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
@@ -126,7 +127,7 @@ fig.show()
126127
#### Simple Example with `datetime` Objects
127128

128129
```python
129-
import plotly.graph_objs as go
130+
import plotly.graph_objects as go
130131
from datetime import datetime
131132

132133
open_data = [33.0, 33.3, 33.5, 33.0, 34.1]

notebooks/distplot.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ For example, the `plotly.express` function `px.histogram` can add a subplot with
4545
```python
4646
import plotly.express as px
4747
tips = px.data.tips()
48-
px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="rug",
49-
hover_data=tips.columns)
48+
fig = px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="rug",
49+
hover_data=tips.columns)
50+
fig.show()
5051
```
5152

5253
```python
5354
import plotly.express as px
5455
tips = px.data.tips()
55-
px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="box", # or violin, rug
56-
hover_data=tips.columns)
56+
fig = px.histogram(tips, x="total_bill", y="tip", color="sex",
57+
marginal="box", # or violin, rug
58+
hover_data=tips.columns)
59+
fig.show()
5760
```
5861

5962
## Combined statistical representations with distplot figure factory
@@ -150,7 +153,7 @@ fig = ff.create_distplot(
150153
[x1, x2], group_labels, bin_size=.2,
151154
rug_text=rug_text, colors=colors)
152155

153-
fig.update(layout_title_text='Customized Distplot')
156+
fig.update_layout(title_text='Customized Distplot')
154157
fig.show()
155158
```
156159

@@ -173,7 +176,7 @@ fig = ff.create_distplot([x1, x2], group_labels, bin_size=.5,
173176
colors=colors)
174177

175178
# Add title
176-
fig.update(layout_title_text='Distplot with Normal Distribution')
179+
fig.update_layout(title_text='Distplot with Normal Distribution')
177180
fig.show()
178181
```
179182

@@ -196,7 +199,7 @@ colors = ['#333F44', '#37AA9C', '#94F3E4']
196199
fig = ff.create_distplot(hist_data, group_labels, show_hist=False, colors=colors)
197200

198201
# Add title
199-
fig.update(layout_title_text='Curve and Rug Plot')
202+
fig.update_layout(title_text='Curve and Rug Plot')
200203
fig.show()
201204
```
202205

@@ -220,7 +223,7 @@ fig = ff.create_distplot(hist_data, group_labels, colors=colors, bin_size=.25,
220223
show_curve=False)
221224

222225
# Add title
223-
fig.update(layout_title_text='Hist and Rug Plot')
226+
fig.update_layout(title_text='Hist and Rug Plot')
224227
fig.show()
225228
```
226229

@@ -267,7 +270,7 @@ fig = ff.create_distplot(hist_data, group_labels, colors=colors,
267270
bin_size=.2, show_rug=False)
268271

269272
# Add title
270-
fig.update(layout_title_text='Hist and Curve Plot')
273+
fig.update_layout(title_text='Hist and Curve Plot')
271274
fig.show()
272275
```
273276

0 commit comments

Comments
 (0)