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/webgl-vs-svg.md
+15-16Lines changed: 15 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -34,17 +34,16 @@ jupyter:
34
34
thumbnail: thumbnail/webgl.jpg
35
35
---
36
36
37
-
For improved performance, consider using WebGL-based traces and Pandas or NumPy objects when creating figures in Plotly.
38
37
39
-
<!-- #region -->
38
+
39
+
40
40
## WebGL
41
41
42
42
`plotly` figures are rendered by web browsers, which broadly speaking have two families of capabilities for rendering graphics:
43
43
44
-
- The SVG API, which supports vector rendering
44
+
- The SVG API, which supports vector rendering.
45
45
- The Canvas API, which supports raster rendering, and can exploit GPU hardware acceleration via a browser technology known as WebGL.
46
46
47
-
48
47
Each `plotly` trace type is rendered with either SVG or WebGL. The following trace types use WebGL for rendering:
49
48
50
49
* Accelerated versions of SVG trace types: `scattergl`, `scatterpolargl`,
@@ -56,16 +55,16 @@ Each `plotly` trace type is rendered with either SVG or WebGL. The following tra
56
55
57
56
WebGL is a powerful technology for accelerating computation but comes with some strict limitations:
58
57
59
-
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
58
+
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.
60
59
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.
61
60
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.
62
-
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)
61
+
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).
63
62
64
63
In addition to the above limitations, the WebGL-powered version of certain SVG-powered trace types (`scattergl`, `scatterpolargl`) are not complete drop-in replacements for their SVG counterparts yet
65
-
* Available symbols will differ
66
-
* Area fills are not yet supported in WebGL
67
-
* Range breaks on time-series axes are not yet supported
68
-
* Axis range heuristics may differ
64
+
* Available symbols will differ.
65
+
* Area fills are not yet supported in WebGL.
66
+
* Range breaks on time-series axes are not yet supported.
67
+
* Axis range heuristics may differ.
69
68
70
69
#### Multiple WebGL Contexts
71
70
@@ -80,7 +79,7 @@ If you encounter WebGL context limits when using WebGL-based figures, you can us
80
79
To use it, in the environment where your Plotly figures are being rendered, load the Virtual WebGL script, "https://unpkg.com/virtual-webgl@1.0.6/src/virtual-webgl.js", for example, using a `<script>` tag.
81
80
82
81
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):
83
-
<!-- #endregion -->
82
+
84
83
85
84
```
86
85
%%html
@@ -96,9 +95,9 @@ it is also possible to use [datashader](/python/datashader/).
96
95
97
96
### WebGL with Plotly Express
98
97
99
-
The `rendermode` argument to supported Plotly Express functions (e.g. `scatter` and `scatter_polar`) can be used to enable WebGL rendering.
98
+
The `render_mode` argument to supported Plotly Express functions (e.g. `scatter` and `scatter_polar`) can be used to enable WebGL rendering.
100
99
101
-
> **Note** The default `rendermode` is `"auto"`, in which case Plotly Express will automatically set `rendermode="webgl"` if the input data is more than 1,000 rows long. If WebGL acceleration is *not* desired in this case, `rendermode` can be forced to `"svg"` for vectorized, if slower, rendering.
100
+
> **Note** The default `render_mode` is `"auto"`, in which case Plotly Express will automatically set `render_mode="webgl"` if the input data is more than 1,000 rows long. In this case, WebGl can be disabled by setting `render_mode=svg`.
102
101
103
102
Here is an example that creates a 100,000 point scatter plot using Plotly Express with WebGL rendering explicitly enabled.
104
103
@@ -107,6 +106,7 @@ import plotly.express as px
107
106
108
107
import pandas as pd
109
108
import numpy as np
109
+
110
110
np.random.seed(1)
111
111
112
112
N =100000
@@ -122,7 +122,7 @@ fig.show()
122
122
```
123
123
124
124
125
-
#### WebGL with 100,000 points with Graph Objects
125
+
#### WebGL with 1,000,000 points with Graph Objects
126
126
127
127
If Plotly Express does not provide a good starting point, it is also possible to use [the more generic `go.Scattergl` class from `plotly.graph_objects`](/python/graph-objects/).
128
128
@@ -131,9 +131,8 @@ import plotly.graph_objects as go
0 commit comments