Skip to content

Commit d0bc21b

Browse files
committed
add back correct examples
1 parent c2d755e commit d0bc21b

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

doc/python/b64.md

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,73 +32,53 @@ jupyter:
3232
thumbnail: thumbnail/b64.png
3333
---
3434

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
3836

3937
```python
4038
import plotly.graph_objects as go
39+
import numpy as np
4140

42-
# x = [-200000 -100000 0 100000 200000]
43-
x = {'dtype': 'int32', 'bdata': 'wPL8/2B5/v8AAAAAoIYBAEANAwA='}
41+
np.random.seed(1)
4442

45-
# y = [0 1 2 3 4 5 6 7 8 9]
46-
y = {'dtype': 'uint8', 'bdata': 'AAECAwQFBgcICQ=='}
43+
N = 10000
4744

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')
6349

64-
fig = go.Figure(data=[go.Surface(
50+
fig = go.Figure(data=[go.Scatter3d(
6551
x=x,
6652
y=y,
67-
z=z
53+
z=z,
54+
marker=dict(color=c),
55+
mode='markers',
56+
opacity=0.2
6857
)])
6958

7059
fig.show()
7160
```
7261

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
7463

7564
```python
7665
import plotly.graph_objects as go
7766
import numpy as np
7867
from base64 import b64encode
7968

80-
def b64(arr) :
81-
return {
82-
'dtype': str(arr.dtype),
83-
'bdata': b64encode(arr).decode('ascii')
84-
}
85-
8669
np.random.seed(1)
8770

88-
N = 10000
71+
M = 100
72+
N = 200
8973

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])
9477

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
10282
)])
10383

10484
fig.show()

0 commit comments

Comments
 (0)