Skip to content

Commit 7a67f81

Browse files
committed
merge performance content
1 parent 170d7f9 commit 7a67f81

File tree

2 files changed

+107
-138
lines changed

2 files changed

+107
-138
lines changed

doc/python/numpy-arrays.md

Lines changed: 0 additions & 129 deletions
This file was deleted.

doc/python/webgl-vs-svg.md

Lines changed: 107 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.16.1
9+
jupytext_version: 1.16.3
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,17 +20,17 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.10.11
23+
version: 3.10.0
2424
plotly:
25-
description: Using WebGL for increased speed, improved interactivity, and the
26-
ability to plot even more data!
25+
description: Using WebGL and NumPy arrays for increased speed, improved interactivity,
26+
and the ability to plot even more data!
2727
display_as: basic
2828
language: python
2929
layout: base
30-
name: WebGL vs SVG
30+
name: High Performance Visualization
3131
order: 14
32-
permalink: python/webgl-vs-svg/
33-
redirect_from: python/compare-webgl-svg/
32+
permalink: python/performance/
33+
redirect_from: python/webgl-vs-svg/
3434
thumbnail: thumbnail/webgl.jpg
3535
---
3636

@@ -72,12 +72,12 @@ To use it, in the environment where your Plotly figures are being rendered, load
7272

7373
In a Jupyter notebook environment that supports magic commands, you can load it with the [HTML magic command](https://ipython.readthedocs.io/en/stable/interactive/magics.html#cellmagic-html):
7474

75-
<!-- #region -->
75+
7676
```
7777
%%html
7878
<script src=“https://unpkg.com/virtual-webgl@1.0.6/src/virtual-webgl.js”></script>
7979
```
80-
<!-- #endregion -->
80+
8181

8282
### WebGL for Scatter Performance
8383

@@ -198,3 +198,101 @@ fig.show()
198198
### Reference
199199

200200
See https://plotly.com/python/reference/scattergl/ for more information and chart attribute options!
201+
202+
## NumPy Arrays
203+
204+
*New in Plotly.py 6.0**
205+
206+
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.
207+
208+
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.
209+
210+
### Arrays and Data Types Supported
211+
212+
The following types of array objects in Python are supported:
213+
214+
- Numpy `numpy.ndarray` objects.
215+
- Pandas Index, `pandas.Index`, or Series, `pandas.Series`, objects.
216+
- Array objects that can be converted to `numpy.ndarray` objects. i.e., they implement `"__array__"` or `"__array_interface__"` and return a `numpy.ndarray`.
217+
218+
The following array data types are supported:
219+
220+
- int8
221+
- uint8
222+
- int16
223+
- uint16
224+
- int32
225+
- uint32
226+
- float32
227+
- float64
228+
- int64*
229+
- uint64*
230+
231+
*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.
232+
233+
### Unsupported Attributes
234+
235+
Arrays passed to attributes with the following names are not supported:
236+
237+
`geojson`, `layers`, and `range`.
238+
239+
240+
### Example with NumPy Arrays
241+
242+
Here, we use NumPy arrays with a `go.Scatter3d` figure.
243+
244+
```python
245+
import plotly.graph_objects as go
246+
import numpy as np
247+
248+
np.random.seed(1)
249+
250+
# Number of data points
251+
N = 10000
252+
253+
# Generate random data
254+
x = np.random.randn(N)
255+
y = np.random.randn(N).astype('float32')
256+
z = np.random.randint(size=N, low=0, high=256, dtype='uint8')
257+
c = np.random.randint(size=N, low=-10, high=10, dtype='int8')
258+
259+
fig = go.Figure(data=[go.Scatter3d(
260+
x=x,
261+
y=y,
262+
z=z,
263+
marker=dict(color=c),
264+
mode='markers',
265+
opacity=0.2
266+
)])
267+
268+
fig.show()
269+
```
270+
271+
### Example with Multi-Dimensional Array
272+
273+
Here, we use a multi dimensional array with a `go.Surface` figure.
274+
275+
276+
```python
277+
import plotly.graph_objects as go
278+
import numpy as np
279+
280+
np.random.seed(1)
281+
282+
# Define the dimensions
283+
M = 100
284+
N = 200
285+
286+
x = np.arange(0, M, 1, dtype='int32')
287+
y = np.arange(0, N, 1, dtype='uint8')
288+
289+
z = np.random.random([N, M])
290+
291+
fig = go.Figure(data=[go.Surface(
292+
x=x,
293+
y=y,
294+
z=z
295+
)])
296+
297+
fig.show()
298+
```

0 commit comments

Comments
 (0)