-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add performance doc #4769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add performance doc #4769
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7770164
add examples using base64
archmoj c2d755e
remove example + make small changes to metadata
LiamConnors d0bc21b
add back correct examples
LiamConnors fb0a5d8
add content for numpy arrays
LiamConnors 49ae498
fix typo
LiamConnors 589d105
rename file
LiamConnors 79afc5c
update titles and link
LiamConnors af1c4a4
fix typo and shorten content
LiamConnors 170d7f9
Update numpy-arrays.md
LiamConnors 7a67f81
merge performance content
LiamConnors f75521c
add intro and restructure svg intro
LiamConnors c895f10
Update webgl-vs-svg.md
LiamConnors 77d7aa3
Update webgl-vs-svg.md
LiamConnors c1e43e7
Update webgl-vs-svg.md
LiamConnors bdfd6af
Update doc/python/webgl-vs-svg.md
LiamConnors 8a3769c
Update doc/python/webgl-vs-svg.md
LiamConnors cf7ac59
change order of dtypes + mention specifying dtype in numpy
LiamConnors 02a9b28
add link to numpy reference docs
LiamConnors 6c6c27b
Merge branch 'master' into add-base64-docs
LiamConnors 56bb8fc
remove extra webgl examples
LiamConnors cdd7839
shorten webgl content
LiamConnors 9ee6b26
small edits + remove extra example
LiamConnors 1325ac1
rename file
LiamConnors 24021f3
add update to types of series
LiamConnors f60f02c
Merge branch 'version-6-migration' into add-base64-docs
LiamConnors File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ jupyter: | |
extension: .md | ||
format_name: markdown | ||
format_version: '1.3' | ||
jupytext_version: 1.16.1 | ||
jupytext_version: 1.16.4 | ||
kernelspec: | ||
display_name: Python 3 (ipykernel) | ||
language: python | ||
|
@@ -20,23 +20,32 @@ jupyter: | |
name: python | ||
nbconvert_exporter: python | ||
pygments_lexer: ipython3 | ||
version: 3.10.11 | ||
version: 3.11.10 | ||
plotly: | ||
description: Using WebGL for increased speed, improved interactivity, and the | ||
ability to plot even more data! | ||
description: Using WebGL and NumPy and Pandas for increased speed, improved interactivity, | ||
and the ability to plot even more data! | ||
display_as: basic | ||
language: python | ||
layout: base | ||
name: WebGL vs SVG | ||
name: High Performance Visualization | ||
order: 14 | ||
permalink: python/webgl-vs-svg/ | ||
redirect_from: python/compare-webgl-svg/ | ||
permalink: python/performance/ | ||
redirect_from: python/webgl-vs-svg/ | ||
thumbnail: thumbnail/webgl.jpg | ||
--- | ||
|
||
### SVG and canvas/WebGL: two browser capabilities for rendering | ||
For improved performance, consider using WebGL-based traces and Pandas or NumPy objects when creating figures in Plotly. | ||
|
||
<!-- #region --> | ||
## WebGL | ||
|
||
`plotly` figures are rendered by web browsers, which broadly speaking have two families of capabilities for rendering graphics: | ||
|
||
- The SVG API, which supports vector rendering | ||
- The Canvas API, which supports raster rendering, and can exploit GPU hardware acceleration via a browser technology known as WebGL. | ||
|
||
`plotly` figures are rendered by web browsers, which broadly speaking have two families of capabilities for rendering graphics: the SVG API which supports vector rendering, and the Canvas API which supports raster rendering, and can exploit GPU hardware acceleration via a browser technology known as WebGL. Each `plotly` trace type is primarily rendered with either SVG or WebGL, although WebGL-powered traces also use some SVG. The following trace types use WebGL for part or all of the rendering: | ||
|
||
Each `plotly` trace type is primarily rendered with either SVG or WebGL, although WebGL-powered traces also use some SVG. The following trace types use WebGL for part or all of the rendering: | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
LiamConnors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
* Accelerated versions of SVG trace types: `scattergl`, `scatterpolargl`, `heatmapgl` | ||
* High-performance multidimensional trace types: `splom`, or `parcoords` | ||
|
@@ -49,7 +58,7 @@ WebGL is a powerful technology for accelerating computation but comes with some | |
|
||
1. GPU requirement: WebGL is a GPU (graphics card) technology and therefore requires specific hardware which is available in most but not all cases and is supported by most but not all browsers | ||
2. Rasterization: WebGL-rendered data is drawn as a grid of pixels rather than as individual shapes, so can appear pixelated or fuzz in certain cases, and when exported to static file formats will appear pixelated on zoom. In addition: text rendering will differ between SVG and WebGL-powered traces. | ||
3. Context limits: browsers impose a strict limit on the number of WebGL "contexts" that any given web document can access. WebGL-powered traces in `plotly` can use multiple contexts in some cases but as a general rule, **it may not be possible to render more than 8 WebGL-involving figures on the same page at the same time.** | ||
3. Context limits: browsers impose a strict limit on the number of WebGL "contexts" that any given web document can access. WebGL-powered traces in `plotly` can use multiple contexts in some cases but as a general rule, **it may not be possible to render more than 8 WebGL-involving figures on the same page at the same time.** See the following section, Multiple WebGL Contexts, for more details. | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
4. Size limits: browsers impose hardware-dependent limits on the height and width of figures using WebGL which users may encounter with extremely large plots (e.g. tens of thousands of pixels of height) | ||
|
||
In addition to the above limitations, the WebGL-powered version of certain SVG-powered trace types (`scattergl`, `scatterpolargl`, `heatmapgl`) are not complete drop-in replacements for their SVG counterparts yet | ||
|
@@ -58,7 +67,7 @@ In addition to the above limitations, the WebGL-powered version of certain SVG-p | |
* Range breaks on time-series axes are not yet supported | ||
* Axis range heuristics may differ | ||
|
||
### Multiple WebGL Contexts | ||
#### Multiple WebGL Contexts | ||
|
||
*New in 5.19* | ||
|
||
|
@@ -71,13 +80,13 @@ If you encounter WebGL context limits when using WebGL-based figures, you can us | |
To use it, in the environment where your Plotly figures are being rendered, load the Virtual WebGL script, "https://unpkg.com/[email protected]/src/virtual-webgl.js", for example, using a `<script>` tag. | ||
|
||
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): | ||
<!-- #endregion --> | ||
|
||
<!-- #region --> | ||
``` | ||
%%html | ||
<script src=“https://unpkg.com/[email protected]/src/virtual-webgl.js”></script> | ||
``` | ||
<!-- #endregion --> | ||
|
||
|
||
### WebGL for Scatter Performance | ||
|
||
|
@@ -198,3 +207,99 @@ fig.show() | |
### Reference | ||
|
||
See https://plotly.com/python/reference/scattergl/ for more information and chart attribute options! | ||
|
||
## Pandas and NumPy for Improved Performance | ||
|
||
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. | ||
|
||
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. | ||
|
||
### Arrays and Data Types Supported | ||
|
||
The following types of objects in Python are supported for improved performance: | ||
|
||
- Numpy `numpy.ndarray` objects. | ||
- Pandas Index, `pandas.Index`, or Series, `pandas.Series`, objects. | ||
- Array objects that can be converted to `numpy.ndarray` objects. i.e., they implement `"__array__"` or `"__array_interface__"` and return a `numpy.ndarray`. | ||
|
||
The following array data types are supported: | ||
|
||
- int8 | ||
- uint8 | ||
LiamConnors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- int16 | ||
- uint16 | ||
- int32 | ||
- uint32 | ||
- float32 | ||
- float64 | ||
LiamConnors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- int64* | ||
- uint64* | ||
|
||
*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. | ||
LiamConnors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Unsupported Attributes | ||
|
||
Arrays passed to attributes with the following names are not supported: | ||
|
||
`geojson`, `layers`, and `range`. | ||
|
||
|
||
### Example with NumPy Arrays | ||
|
||
Here, we use NumPy arrays with a `go.Scatter3d` figure. | ||
|
||
```python | ||
import plotly.graph_objects as go | ||
import numpy as np | ||
|
||
np.random.seed(1) | ||
|
||
# Number of data points | ||
N = 10000 | ||
|
||
# Generate random data | ||
x = np.random.randn(N) | ||
y = np.random.randn(N).astype('float32') | ||
z = np.random.randint(size=N, low=0, high=256, dtype='uint8') | ||
c = np.random.randint(size=N, low=-10, high=10, dtype='int8') | ||
|
||
fig = go.Figure(data=[go.Scatter3d( | ||
x=x, | ||
y=y, | ||
z=z, | ||
marker=dict(color=c), | ||
mode='markers', | ||
opacity=0.2 | ||
)]) | ||
|
||
fig.show() | ||
``` | ||
|
||
### Example with Multi-Dimensional Array | ||
|
||
Here, we use a multi dimensional array with a `go.Surface` figure. | ||
|
||
|
||
```python | ||
import plotly.graph_objects as go | ||
import numpy as np | ||
|
||
np.random.seed(1) | ||
|
||
# Define the dimensions | ||
M = 100 | ||
N = 200 | ||
|
||
x = np.arange(0, M, 1, dtype='int32') | ||
y = np.arange(0, N, 1, dtype='uint8') | ||
|
||
z = np.random.random([N, M]) | ||
|
||
fig = go.Figure(data=[go.Surface( | ||
x=x, | ||
y=y, | ||
z=z | ||
)]) | ||
|
||
fig.show() | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.