You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/python/performance.md
+71-67
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,77 @@ jupyter:
36
36
thumbnail: thumbnail/webgl.jpg
37
37
---
38
38
39
+
## DataFrames Types
40
+
41
+
Plotly Express natively supports [pandas, Polars, PyArrow, and Modin dataframes](/python/px-arguments). When building figures with Plotly Express, changing your dataframe library may help improve performance.
42
+
43
+
## NumPy and NumPy Convertible Arrays for Improved Performance
44
+
45
+
*New in Plotly.py version 6*
46
+
47
+
Improve the performance of generating Plotly figures that use a large number of data points by using NumPy arrays and other objects that Plotly can convert to NumPy arrays, such as Pandas and Polars Series.
48
+
49
+
Plotly.py uses Plotly.js for rendering, which supports typed arrays. In Plotly.py, NumPy array and NumPy-convertible arrays are base64 encoded before being passed to Plotly.js for rendering.
50
+
51
+
### Arrays and Data Types Supported
52
+
53
+
The following types of objects in Python are supported for improved performance:
- Array objects that can be converted to `numpy.ndarray` objects. i.e., they implement `"__array__"` or `"__array_interface__"` and return a `numpy.ndarray`.
58
+
59
+
The following [array data types](https://numpy.org/devdocs/reference/arrays.scalars.html) are supported:
60
+
61
+
- float32
62
+
- float64
63
+
- int8
64
+
- uint8
65
+
- int16
66
+
- uint16
67
+
- int32
68
+
- uint32
69
+
70
+
*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. When working with NumPY directly, you can [specify the `dtype`](https://numpy.org/doc/stable/user/basics.types.html#array-types-and-conversions-between-types) when creating `ndarray` objects.
71
+
72
+
### Unsupported Attributes
73
+
74
+
Arrays passed to attributes with the following names are not supported:
75
+
76
+
`geojson`, `layers`, and `range`.
77
+
78
+
79
+
### Example with NumPy Arrays
80
+
81
+
Here, we use NumPy arrays with a `go.Scatter3d` figure.
82
+
83
+
```python
84
+
import plotly.graph_objects as go
85
+
import numpy as np
86
+
87
+
np.random.seed(1)
88
+
89
+
# Number of data points
90
+
N =10000
91
+
92
+
# Generate random data
93
+
x = np.random.randn(N)
94
+
y = np.random.randn(N).astype('float32')
95
+
z = np.random.randint(size=N, low=0, high=256, dtype='uint8')
96
+
c = np.random.randint(size=N, low=-10, high=10, dtype='int8')
97
+
98
+
fig = go.Figure(data=[go.Scatter3d(
99
+
x=x,
100
+
y=y,
101
+
z=z,
102
+
marker=dict(color=c),
103
+
mode='markers',
104
+
opacity=0.2
105
+
)])
106
+
107
+
fig.show()
108
+
```
109
+
39
110
## WebGL
40
111
41
112
`plotly` figures are rendered by web browsers, which broadly speaking have two families of capabilities for rendering graphics:
@@ -152,73 +223,6 @@ fig.show()
152
223
153
224
See https://plotly.com/python/reference/scattergl/ for more information and chart attribute options!
154
225
155
-
## NumPy and NumPy Convertible Arrays for Improved Performance
156
-
157
-
*New in Plotly.py version 6*
158
-
159
-
Improve the performance of generating Plotly figures that use a large number of data points by using NumPy arrays and other objects that Plotly can convert to NumPy arrays, such as Pandas and Polars Series.
160
-
161
-
Plotly.py uses Plotly.js for rendering, which supports typed arrays. In Plotly.py, NumPy array and NumPy-convertible arrays are base64 encoded before being passed to Plotly.js for rendering.
162
-
163
-
### Arrays and Data Types Supported
164
-
165
-
The following types of objects in Python are supported for improved performance:
- Array objects that can be converted to `numpy.ndarray` objects. i.e., they implement `"__array__"` or `"__array_interface__"` and return a `numpy.ndarray`.
170
-
171
-
The following [array data types](https://numpy.org/devdocs/reference/arrays.scalars.html) are supported:
172
-
173
-
- float32
174
-
- float64
175
-
- int8
176
-
- uint8
177
-
- int16
178
-
- uint16
179
-
- int32
180
-
- uint32
181
-
182
-
*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. When working with NumPY directly, you can [specify the `dtype`](https://numpy.org/doc/stable/user/basics.types.html#array-types-and-conversions-between-types) when creating `ndarray` objects.
183
-
184
-
### Unsupported Attributes
185
-
186
-
Arrays passed to attributes with the following names are not supported:
187
-
188
-
`geojson`, `layers`, and `range`.
189
-
190
-
191
-
### Example with NumPy Arrays
192
-
193
-
Here, we use NumPy arrays with a `go.Scatter3d` figure.
194
-
195
-
```python
196
-
import plotly.graph_objects as go
197
-
import numpy as np
198
-
199
-
np.random.seed(1)
200
-
201
-
# Number of data points
202
-
N =10000
203
-
204
-
# Generate random data
205
-
x = np.random.randn(N)
206
-
y = np.random.randn(N).astype('float32')
207
-
z = np.random.randint(size=N, low=0, high=256, dtype='uint8')
208
-
c = np.random.randint(size=N, low=-10, high=10, dtype='int8')
209
-
210
-
fig = go.Figure(data=[go.Scatter3d(
211
-
x=x,
212
-
y=y,
213
-
z=z,
214
-
marker=dict(color=c),
215
-
mode='markers',
216
-
opacity=0.2
217
-
)])
218
-
219
-
fig.show()
220
-
```
221
-
222
226
## Datashader
223
227
224
228
Use [Datashader](https://datashader.org/) to reduce the size of a dataset passed to the browser for rendering by creating a rasterized representation of the dataset. This makes it ideal for working with datasets of tens to hundreds of millions of points.
0 commit comments