@@ -32,73 +32,53 @@ jupyter:
32
32
thumbnail : thumbnail/b64.png
33
33
---
34
34
35
- ``` python
36
- # ## Simple example showing how arrays of numbers could be passed as base64 typed array objects to plotly.js
37
- ```
35
+ ### Example where base64 is automatically applied to pass numpy arrays to plotly.js
38
36
39
37
``` python
40
38
import plotly.graph_objects as go
39
+ import numpy as np
41
40
42
- # x = [-200000 -100000 0 100000 200000]
43
- x = {' dtype' : ' int32' , ' bdata' : ' wPL8/2B5/v8AAAAAoIYBAEANAwA=' }
41
+ np.random.seed(1 )
44
42
45
- # y = [0 1 2 3 4 5 6 7 8 9]
46
- y = {' dtype' : ' uint8' , ' bdata' : ' AAECAwQFBgcICQ==' }
43
+ N = 10000
47
44
48
- # z = [
49
- # [ 61 -295 -765 863 932]
50
- # [-897 96 724 791 -993]
51
- # [ -95 -796 -285 381 669]
52
- # [ 985 -153 425 -40 136]
53
- # [-856 955 -871 414 996]
54
- # [ 966 607 -154 -251 -882]
55
- # [-492 -116 414 426 305]
56
- # [ 919 202 -505 300 -833]
57
- # [ 278 -152 -643 -950 -86]
58
- # [ 898 -532 608 -93 110]]
59
- z = {
60
- ' dtype' : ' int16' ,
61
- ' bdata' : ' PQDZ/gP9XwOkA3/8YADUAhcDH/yh/+T84/59AZ0C2QNn/6kB2P+IAKj8uwOZ/J4B5APGA18CZv8F/478FP6M/54BqgExAZcDygAH/iwBv/wWAWj/ff1K/Kr/ggPs/WACo/9uAA==' , ' shape' : ' 10, 5'
62
- }
45
+ x = np.random.randn(N)
46
+ y = np.random.randn(N).astype(' float32' )
47
+ z = np.random.randint(size = N, low = 0 , high = 256 , dtype = ' uint8' )
48
+ c = np.random.randint(size = N, low = - 10 , high = 10 , dtype = ' int8' )
63
49
64
- fig = go.Figure(data = [go.Surface (
50
+ fig = go.Figure(data = [go.Scatter3d (
65
51
x = x,
66
52
y = y,
67
- z = z
53
+ z = z,
54
+ marker = dict (color = c),
55
+ mode = ' markers' ,
56
+ opacity = 0.2
68
57
)])
69
58
70
59
fig.show()
71
60
```
72
61
73
- ### Example where base64 is applied to pass values as typed array objects to plotly.js
62
+ ### Example where base64 is automatically applied to pass multi-dimensional numpy arrays to plotly.js
74
63
75
64
``` python
76
65
import plotly.graph_objects as go
77
66
import numpy as np
78
67
from base64 import b64encode
79
68
80
- def b64 (arr ) :
81
- return {
82
- ' dtype' : str (arr.dtype),
83
- ' bdata' : b64encode(arr).decode(' ascii' )
84
- }
85
-
86
69
np.random.seed(1 )
87
70
88
- N = 10000
71
+ M = 100
72
+ N = 200
89
73
90
- x = np.random.randn(N)
91
- y = np.random.randn(N).astype(' float32' )
92
- z = np.random.randint(size = N, low = 0 , high = 256 , dtype = ' uint8' )
93
- c = np.random.randint(size = N, low = - 10 , high = 10 , dtype = ' int8' )
74
+ x = np.arange(0 , M, 1 , ' int32' )
75
+ y = np.arange(0 , N, 1 , ' uint8' )
76
+ z = np.random.random([N, M])
94
77
95
- fig = go.Figure(data = [go.Scatter3d(
96
- x = b64(x),
97
- y = b64(y),
98
- z = b64(z),
99
- marker = dict (color = b64(c)),
100
- mode = ' markers' ,
101
- opacity = 0.2
78
+ fig = go.Figure(data = [go.Surface(
79
+ x = x,
80
+ y = y,
81
+ z = z
102
82
)])
103
83
104
84
fig.show()
0 commit comments