Skip to content

Commit cdd7839

Browse files
committed
shorten webgl content
1 parent 56bb8fc commit cdd7839

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

doc/python/webgl-vs-svg.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,16 @@ jupyter:
3434
thumbnail: thumbnail/webgl.jpg
3535
---
3636

37-
For improved performance, consider using WebGL-based traces and Pandas or NumPy objects when creating figures in Plotly.
3837

39-
<!-- #region -->
38+
39+
4040
## WebGL
4141

4242
`plotly` figures are rendered by web browsers, which broadly speaking have two families of capabilities for rendering graphics:
4343

44-
- The SVG API, which supports vector rendering
44+
- The SVG API, which supports vector rendering.
4545
- The Canvas API, which supports raster rendering, and can exploit GPU hardware acceleration via a browser technology known as WebGL.
4646

47-
4847
Each `plotly` trace type is rendered with either SVG or WebGL. The following trace types use WebGL for rendering:
4948

5049
* 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
5655

5756
WebGL is a powerful technology for accelerating computation but comes with some strict limitations:
5857

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.
6059
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.
6160
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).
6362

6463
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.
6968

7069
#### Multiple WebGL Contexts
7170

@@ -80,7 +79,7 @@ If you encounter WebGL context limits when using WebGL-based figures, you can us
8079
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.
8180

8281
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+
8483

8584
```
8685
%%html
@@ -96,9 +95,9 @@ it is also possible to use [datashader](/python/datashader/).
9695

9796
### WebGL with Plotly Express
9897

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.
10099

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`.
102101
103102
Here is an example that creates a 100,000 point scatter plot using Plotly Express with WebGL rendering explicitly enabled.
104103

@@ -107,6 +106,7 @@ import plotly.express as px
107106

108107
import pandas as pd
109108
import numpy as np
109+
110110
np.random.seed(1)
111111

112112
N = 100000
@@ -122,7 +122,7 @@ fig.show()
122122
```
123123

124124

125-
#### WebGL with 100,000 points with Graph Objects
125+
#### WebGL with 1,000,000 points with Graph Objects
126126

127127
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/).
128128

@@ -131,9 +131,8 @@ import plotly.graph_objects as go
131131

132132
import numpy as np
133133

134-
N = 100000
134+
N = 1_000_000
135135

136-
# Create figure
137136
fig = go.Figure()
138137

139138
fig.add_trace(

0 commit comments

Comments
 (0)