@@ -34,6 +34,7 @@ jupyter:
34
34
permalink : python/3d-axes/
35
35
thumbnail : thumbnail/your-tutorial-chart.jpg
36
36
title : Format 3d Axes | plotly
37
+ v4upgrade : true
37
38
---
38
39
39
40
### Range of axes
@@ -47,21 +48,21 @@ import plotly.graph_objs as go
47
48
import numpy as np
48
49
49
50
N = 70
50
- trace1 = go.Mesh3d(x = (70 * np.random.randn(N)),
51
+
52
+ fig = go.Figure(data = [go.Mesh3d(x = (70 * np.random.randn(N)),
51
53
y = (55 * np.random.randn(N)),
52
54
z = (40 * np.random.randn(N)),
53
55
opacity = 0.5 ,
54
56
color = ' rgba(244,22,100,0.6)'
55
- )
57
+ )])
56
58
57
- layout = go.Layout(scene = dict (
59
+ fig.update( layout = go.Layout(scene = dict (
58
60
xaxis = dict (nticks = 4 , range = [- 100 ,100 ],),
59
61
yaxis = dict (nticks = 4 , range = [- 50 ,100 ],),
60
62
zaxis = dict (nticks = 4 , range = [- 100 ,100 ],),),
61
63
width = 700 ,
62
- margin = dict (r = 20 , l = 10 , b = 10 , t = 10 ))
64
+ margin = dict (r = 20 , l = 10 , b = 10 , t = 10 )))
63
65
64
- fig = go.Figure(data = [trace1], layout = layout)
65
66
fig.show()
66
67
```
67
68
@@ -110,27 +111,27 @@ import numpy as np
110
111
111
112
# Define random surface
112
113
N = 50
113
- trace1 = go.Mesh3d(x = (60 * np.random.randn(N)),
114
+ fig = go.Figure()
115
+ fig.add_trace(go.Mesh3d(x = (60 * np.random.randn(N)),
114
116
y = (25 * np.random.randn(N)),
115
117
z = (40 * np.random.randn(N)),
116
118
opacity = 0.5 ,
117
119
color = ' yellow'
118
- )
119
- trace2 = go.Mesh3d(x = (70 * np.random.randn(N)),
120
+ ))
121
+ fig.add_trace( go.Mesh3d(x = (70 * np.random.randn(N)),
120
122
y = (55 * np.random.randn(N)),
121
123
z = (30 * np.random.randn(N)),
122
124
opacity = 0.5 ,
123
125
color = ' pink'
124
- )
126
+ ))
125
127
126
- layout = go.Layout(scene = dict (
128
+ fig.update( layout = go.Layout(scene = dict (
127
129
xaxis_title = ' X AXIS TITLE' ,
128
130
yaxis_title = ' Y AXIS TITLE' ,
129
131
zaxis_title = ' Z AXIS TITLE' ),
130
132
width = 700 ,
131
- margin = dict (r = 20 , b = 10 , l = 10 , t = 10 ))
133
+ margin = dict (r = 20 , b = 10 , l = 10 , t = 10 )))
132
134
133
- fig = go.Figure(data = [trace1,trace2], layout = layout)
134
135
fig.show()
135
136
```
136
137
@@ -142,15 +143,15 @@ import numpy as np
142
143
143
144
# Define random surface
144
145
N = 50
145
- trace1 = go.Mesh3d(x = (60 * np.random.randn(N)),
146
+ fig = go.Figure( data = [ go.Mesh3d(x = (60 * np.random.randn(N)),
146
147
y = (25 * np.random.randn(N)),
147
148
z = (40 * np.random.randn(N)),
148
149
opacity = 0.5 ,
149
150
color = ' rgba(100,22,200,0.5)'
150
- )
151
+ )])
151
152
152
153
# Different types of customized ticks
153
- layout = go.Layout(
154
+ fig.update( layout = go.Layout(
154
155
scene = dict (
155
156
xaxis = dict (
156
157
ticktext = [' TICKS' ,' MESH' ,' PLOTLY' ,' PYTHON' ],
@@ -166,8 +167,8 @@ layout = go.Layout(
166
167
tick0 = 0 , tickwidth = 4 ),),
167
168
width = 700 ,
168
169
margin = dict (r = 10 , l = 10 , b = 10 , t = 10 )
169
- )
170
- fig = go.Figure( data = [trace1], layout = layout)
170
+ ))
171
+
171
172
fig.show()
172
173
```
173
174
@@ -178,14 +179,14 @@ import plotly.graph_objs as go
178
179
import numpy as np
179
180
180
181
N = 50
181
- trace1 = go.Mesh3d(x = (30 * np.random.randn(N)),
182
+ fig = go.Figure( data = [ go.Mesh3d(x = (30 * np.random.randn(N)),
182
183
y = (25 * np.random.randn(N)),
183
184
z = (30 * np.random.randn(N)),
184
- opacity = 0.5 ,)
185
+ opacity = 0.5 ,)])
185
186
186
187
187
188
# xaxis.backgroundcolor is used to set background color
188
- layout = go.Layout(
189
+ fig.update( layout = go.Layout(
189
190
scene = dict (
190
191
xaxis = dict (
191
192
backgroundcolor = " rgb(200, 200, 230)" ,
@@ -206,7 +207,10 @@ layout = go.Layout(
206
207
margin = dict (
207
208
r = 10 , l = 10 ,
208
209
b = 10 , t = 10 )
209
- )
210
- fig = go.Figure(data = [trace1], layout = layout)
210
+ ))
211
211
fig.show()
212
212
```
213
+
214
+ ``` python
215
+
216
+ ```
0 commit comments