6
6
extension : .md
7
7
format_name : markdown
8
8
format_version : ' 1.3'
9
- jupytext_version : 1.15.2
9
+ jupytext_version : 1.16.3
10
10
kernelspec :
11
11
display_name : Python 3 (ipykernel)
12
12
language : python
@@ -20,20 +20,21 @@ jupyter:
20
20
name : python
21
21
nbconvert_exporter : python
22
22
pygments_lexer : ipython3
23
- version : 3.9 .0
23
+ version : 3.10 .0
24
24
plotly :
25
- description : How to format axes of 3d plots in Python with Plotly.
26
- display_as : b64
25
+ description : How to use typed arrays in Plotly.py
26
+ display_as : file_settings
27
27
language : python
28
28
layout : base
29
- name : b64
30
- order : 1
31
- page_type : example_index
29
+ name : Improving Performance with Typed Arrays
30
+ order : 39
32
31
permalink : python/b64/
33
32
thumbnail : thumbnail/b64.png
34
33
---
35
34
35
+ ``` python
36
36
# ## Simple example showing how arrays of numbers could be passed as base64 typed array objects to plotly.js
37
+ ```
37
38
38
39
``` python
39
40
import plotly.graph_objects as go
@@ -102,97 +103,3 @@ fig = go.Figure(data=[go.Scatter3d(
102
103
103
104
fig.show()
104
105
```
105
-
106
- ### Similar example where base64 is automatically applied to pass numpy arrays to plotly.js
107
-
108
- ``` python
109
- import plotly.graph_objects as go
110
- import numpy as np
111
-
112
- np.random.seed(1 )
113
-
114
- N = 10000
115
-
116
- x = np.random.randn(N)
117
- y = np.random.randn(N).astype(' float32' )
118
- z = np.random.randint(size = N, low = 0 , high = 256 , dtype = ' uint8' )
119
- c = np.random.randint(size = N, low = - 10 , high = 10 , dtype = ' int8' )
120
-
121
- fig = go.Figure(data = [go.Scatter3d(
122
- x = x,
123
- y = y,
124
- z = z,
125
- marker = dict (color = c),
126
- mode = ' markers' ,
127
- opacity = 0.2
128
- )])
129
-
130
- fig.show()
131
- ```
132
-
133
-
134
- ### Example where base64 is applied to pass 2 dimensional values as typed array objects to plotly.js using shape in the spec
135
-
136
- ``` python
137
- import plotly.graph_objects as go
138
- import numpy as np
139
- from base64 import b64encode
140
-
141
- def b64 (arr ) :
142
- return {
143
- ' dtype' : str (arr.dtype),
144
- ' bdata' : b64encode(arr).decode(' ascii' ),
145
- ' shape' : None if arr.ndim == 1 else str (arr.shape)[1 :- 1 ]
146
- }
147
-
148
- np.random.seed(1 )
149
-
150
- M = 100
151
- N = 200
152
-
153
- x = np.arange(0 , M, 1 , ' int32' )
154
- y = np.arange(0 , N, 1 , ' uint8' )
155
- z = np.random.random([N, M])
156
-
157
- fig = go.Figure(data = [go.Surface(
158
- x = b64(x),
159
- y = b64(y),
160
- z = b64(z)
161
- )])
162
-
163
- fig.show()
164
- ```
165
-
166
- ### Similar example where base64 is automatically applied to pass multi-dimensional numpy arrays to plotly.js
167
-
168
- ``` python
169
- import plotly.graph_objects as go
170
- import numpy as np
171
- from base64 import b64encode
172
-
173
- np.random.seed(1 )
174
-
175
- M = 100
176
- N = 200
177
-
178
- x = np.arange(0 , M, 1 , ' int32' )
179
- y = np.arange(0 , N, 1 , ' uint8' )
180
- z = np.random.random([N, M])
181
-
182
- fig = go.Figure(data = [go.Surface(
183
- x = x,
184
- y = y,
185
- z = z
186
- )])
187
-
188
- fig.show()
189
- ```
190
-
191
-
192
- ``` python
193
-
194
- ```
195
-
196
- ``` python
197
-
198
- ```
0 commit comments