6
6
extension : .md
7
7
format_name : markdown
8
8
format_version : ' 1.1'
9
- jupytext_version : 1.1.6
9
+ jupytext_version : 1.1.1
10
10
kernelspec :
11
11
display_name : Python 3
12
12
language : python
@@ -33,7 +33,6 @@ jupyter:
33
33
order : 32
34
34
permalink : python/shapes/
35
35
thumbnail : thumbnail/shape.jpg
36
-
37
36
v4upgrade : true
38
37
---
39
38
@@ -59,8 +58,7 @@ fig.update_xaxes(range=[0, 7])
59
58
fig.update_yaxes(range = [0 , 2.5 ])
60
59
61
60
# Add shapes
62
- fig.update_layout(
63
- shapes = [
61
+ fig.add_shape(
64
62
# Line Vertical
65
63
go.layout.Shape(
66
64
type = " line" ,
@@ -72,7 +70,8 @@ fig.update_layout(
72
70
color = " RoyalBlue" ,
73
71
width = 3
74
72
)
75
- ),
73
+ ))
74
+ fig.add_shape(
76
75
# Line Horizontal
77
76
go.layout.Shape(
78
77
type = " line" ,
@@ -85,7 +84,8 @@ fig.update_layout(
85
84
width = 4 ,
86
85
dash = " dashdot" ,
87
86
),
88
- ),
87
+ ))
88
+ fig.add_shape(
89
89
# Line Diagonal
90
90
go.layout.Shape(
91
91
type = " line" ,
@@ -97,11 +97,9 @@ fig.update_layout(
97
97
color = " MediumPurple" ,
98
98
width = 4 ,
99
99
dash = " dot" ,
100
- ),
101
- ),
102
- ]
103
- )
104
-
100
+ )
101
+ ))
102
+ fig.update_shapes(dict (xref = ' x' , yref = ' y' ))
105
103
fig.show()
106
104
```
107
105
@@ -126,8 +124,7 @@ fig.update_xaxes(range=[0, 8])
126
124
fig.update_yaxes(range = [0 , 2 ])
127
125
128
126
# Add shapes
129
- fig.update_layout(
130
- shapes = [
127
+ fig.add_shape(
131
128
# Line reference to the axes
132
129
go.layout.Shape(
133
130
type = " line" ,
@@ -141,7 +138,8 @@ fig.update_layout(
141
138
color = " LightSeaGreen" ,
142
139
width = 3 ,
143
140
),
144
- ),
141
+ ))
142
+ fig.add_shape(
145
143
# Line reference to the plot
146
144
go.layout.Shape(
147
145
type = " line" ,
@@ -156,7 +154,6 @@ fig.update_layout(
156
154
width = 3 ,
157
155
),
158
156
),
159
- ]
160
157
)
161
158
162
159
fig.show()
@@ -169,7 +166,7 @@ import plotly.graph_objects as go
169
166
170
167
import numpy as np
171
168
172
- # Generate date
169
+ # Generate data
173
170
x0 = np.linspace(1 , 3 , 200 )
174
171
y0 = x0 * np.sin(np.power(x0, 2 )) + 1
175
172
@@ -187,47 +184,38 @@ fig.update_layout(
187
184
)
188
185
189
186
# Add tangent line shapes
190
- fig.update_layout(
191
- shapes = [
187
+ fig.add_shape(
192
188
go.layout.Shape(
193
189
type = " line" ,
194
190
x0 = 1 ,
195
191
y0 = 2.30756 ,
196
192
x1 = 1.75 ,
197
193
y1 = 2.30756 ,
198
- opacity = 0.7 ,
199
- line = dict (
200
- color = " Crimson" ,
201
- width = 2.5 ,
202
- ),
203
- ),
194
+ ))
195
+ fig.add_shape(
204
196
go.layout.Shape(
205
197
type = " line" ,
206
198
x0 = 2.5 ,
207
199
y0 = 3.80796 ,
208
200
x1 = 3.05 ,
209
201
y1 = 3.80796 ,
210
- opacity = 0.7 ,
211
- line = dict (
212
- color = " Crimson" ,
213
- width = 2.5 ,
214
- ),
215
- ),
202
+ ))
203
+ fig.add_shape(
216
204
go.layout.Shape(
217
205
type = " line" ,
218
206
x0 = 1.90 ,
219
207
y0 = - 1.1827 ,
220
208
x1 = 2.50 ,
221
209
y1 = - 1.1827 ,
222
- opacity = 0.7 ,
223
- line = dict (
224
- color = " Crimson " ,
225
- width = 2.5 ,
226
- ) ,
227
- ),
228
- ]
229
- )
230
-
210
+ ))
211
+ fig.update_shapes( dict (
212
+ xref = " x " ,
213
+ yref = " y " ,
214
+ opacity = 0.7 ,
215
+ line = dict (
216
+ color = " Crimson " ,
217
+ width = 2.5 ,
218
+ )))
231
219
fig.show()
232
220
```
233
221
@@ -250,8 +238,7 @@ fig.update_xaxes(range=[0, 7], showgrid=False)
250
238
fig.update_yaxes(range = [0 , 3.5 ])
251
239
252
240
# Add shapes
253
- fig.update_layout(
254
- shapes = [
241
+ fig.add_shape(
255
242
# unfilled Rectangle
256
243
go.layout.Shape(
257
244
type = " rect" ,
@@ -262,7 +249,8 @@ fig.update_layout(
262
249
line = dict (
263
250
color = " RoyalBlue" ,
264
251
),
265
- ),
252
+ ))
253
+ fig.add_shape(
266
254
# filled Rectangle
267
255
go.layout.Shape(
268
256
type = " rect" ,
@@ -275,10 +263,8 @@ fig.update_layout(
275
263
width = 2 ,
276
264
),
277
265
fillcolor = " LightSkyBlue" ,
278
- ),
279
- ]
280
- )
281
-
266
+ ))
267
+ fig.update_shapes(dict (xref = ' x' , yref = ' y' ))
282
268
fig.show()
283
269
```
284
270
@@ -303,8 +289,7 @@ fig.update_xaxes(range=[0, 4], showgrid=False)
303
289
fig.update_yaxes(range = [0 , 4 ])
304
290
305
291
# Add shapes
306
- fig.update_layout(
307
- shapes = [
292
+ fig.add_shape(
308
293
# Rectangle reference to the axes
309
294
go.layout.Shape(
310
295
type = " rect" ,
@@ -319,7 +304,8 @@ fig.update_layout(
319
304
width = 3 ,
320
305
),
321
306
fillcolor = " LightSkyBlue" ,
322
- ),
307
+ ))
308
+ fig.add_shape(
323
309
# Rectangle reference to the plot
324
310
go.layout.Shape(
325
311
type = " rect" ,
@@ -334,9 +320,7 @@ fig.update_layout(
334
320
width = 3 ,
335
321
),
336
322
fillcolor = " PaleTurquoise" ,
337
- ),
338
- ]
339
- )
323
+ ))
340
324
341
325
fig.show()
342
326
```
@@ -596,37 +580,32 @@ fig.update_yaxes(
596
580
)
597
581
598
582
# Add circles
599
- fig.update_layout(
600
- shapes = [
583
+ fig.add_shape(
601
584
go.layout.Shape(
602
- opacity = 0.3 ,
603
- xref = " x" ,
604
- yref = " y" ,
585
+ type = " circle" ,
605
586
fillcolor = " blue" ,
606
587
x0 = 0 ,
607
588
y0 = 0 ,
608
589
x1 = 2 ,
609
590
y1 = 2 ,
610
- type = " circle" ,
611
- line_color = " blue" ,
612
- layer = " below"
613
- ),
591
+ line_color = " blue"
592
+ ))
593
+ fig.add_shape(
614
594
go.layout.Shape(
615
- opacity = 0.3 ,
616
- xref = " x" ,
617
- yref = " y" ,
595
+ type = " circle" ,
618
596
fillcolor = " gray" ,
619
597
x0 = 1.5 ,
620
598
y0 = 0 ,
621
599
x1 = 3.5 ,
622
600
y1 = 2 ,
623
- type = " circle" ,
624
- line_color = " gray" ,
625
- layer = " below"
626
- )
627
- ],
628
- )
629
-
601
+ line_color = " gray"
602
+ ))
603
+ fig.update_shapes(dict (
604
+ opacity = 0.3 ,
605
+ xref = " x" ,
606
+ yref = " y" ,
607
+ layer = " below"
608
+ ))
630
609
# Update figure dimensions
631
610
fig.update_layout(
632
611
margin = dict (
0 commit comments