Skip to content

Commit fb0a5d8

Browse files
committed
add content for numpy arrays
1 parent d0bc21b commit fb0a5d8

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

doc/python/b64.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,59 @@ jupyter:
3232
thumbnail: thumbnail/b64.png
3333
---
3434

35-
### Example where base64 is automatically applied to pass numpy arrays to plotly.js
35+
*New in Plotly.py 6.0**
36+
37+
Improve the performance of generating Plotly figures that use a large number of data points by using NumPy arrays and other objects that can be converted to NumPy arrays, such as Pandas Series and Index objects.
38+
39+
Plotly.py uses Plotly.js for rendering, which supports base64-encoded typed arrays. In Plotly.py, NumPy array and NumPy-convertible arrays are base64 encoded before being passed to Plotly.js for rendering.
40+
41+
42+
## Arrays and Data Types Supported
43+
44+
The following types of array objects in Python are supported:
45+
46+
- Numpy `numpy.ndarray` objects.
47+
- Pandas Index, `pandas.Index`, or Series, `pandas.Series`, objects.
48+
- Array objects that can be converted to `numpy.ndarray` objects. i.e., they implement `"__array__"` or `"__array_interface__"` and return a `numpy.ndarray.
49+
50+
The following array data types are supported:
51+
52+
- int8
53+
- uint8
54+
- int16
55+
- uint16
56+
- int32
57+
- uint32
58+
- float32
59+
- float64
60+
- int64*
61+
- uint64*
62+
63+
*If the array dtype is **int64** and **uint64**, often the default dtype for arrays in NumPy when no dtype is specified, those dtypes will be changed to other types internally by Plotly.py where possible.
64+
65+
66+
67+
## Unsupported Attributes
68+
69+
Arrays passsed to attributes with the following names do not use the Plotly.js base64 typed arrays functionality:
70+
71+
`geojson`, `layers`, and `range`.
72+
73+
74+
## Example with NumPy Arrays
75+
76+
Here, we use NumPy arrays with a `go.Scatter3d` figure.
3677

3778
```python
3879
import plotly.graph_objects as go
3980
import numpy as np
4081

4182
np.random.seed(1)
4283

84+
# Number of data points
4385
N = 10000
4486

87+
# Generate random data
4588
x = np.random.randn(N)
4689
y = np.random.randn(N).astype('float32')
4790
z = np.random.randint(size=N, low=0, high=256, dtype='uint8')
@@ -59,20 +102,24 @@ fig = go.Figure(data=[go.Scatter3d(
59102
fig.show()
60103
```
61104

62-
### Example where base64 is automatically applied to pass multi-dimensional numpy arrays to plotly.js
105+
### Example with Multi-Dimensional Array
106+
107+
Here, we use a multi dimensional array with a `go.Surface` figure.
108+
63109

64110
```python
65111
import plotly.graph_objects as go
66112
import numpy as np
67-
from base64 import b64encode
68113

69114
np.random.seed(1)
70115

116+
# Define the dimensions
71117
M = 100
72118
N = 200
73119

74-
x = np.arange(0, M, 1, 'int32')
75-
y = np.arange(0, N, 1, 'uint8')
120+
x = np.arange(0, M, 1, dtype='int32')
121+
y = np.arange(0, N, 1, dtype='uint8')
122+
76123
z = np.random.random([N, M])
77124

78125
fig = go.Figure(data=[go.Surface(

0 commit comments

Comments
 (0)