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/renderers.md
+10-6
Original file line number
Diff line number
Diff line change
@@ -40,11 +40,11 @@ Plotly's Python graphing library, `plotly.py`, gives you a wide range of options
40
40
41
41
In general, there are five different approaches you can take in order to display `plotly` figures:
42
42
43
-
1. Using the `renderers` framework in the context of a script or notebook
43
+
1. Using the `renderers` framework in the context of a script or notebook (the main topic of this page)
44
44
2. Using [Dash](https://dash.plot.ly) in a web app context
45
-
3. Using a `FigureWidget` in an `ipywidgets` context
46
-
4. By [exporting to an HTML file](https://plotly.com/python/interactive-html-export/) and loading that file in a browser
47
-
5. By [rendering the figure to a static representation](https://plotly.com/python/static-image-export/) such as PNG, JPEG, SVG, PDF or EPS
45
+
3. Using a [`FigureWidget`rather than a `Figure`](https://plotly.com/python/figurewidget/)in an [`ipywidgets` context](https://ipywidgets.readthedocs.io/en/stable/)
46
+
4. By [exporting to an HTML file](https://plotly.com/python/interactive-html-export/) and loading that file in a browser immediately or later
47
+
5. By [rendering the figure to a static image file using Kaleido](https://plotly.com/python/static-image-export/) such as PNG, JPEG, SVG, PDF or EPS and loading the resulting file in any viewer
48
48
49
49
Each of the first three approaches is discussed below.
50
50
@@ -251,6 +251,10 @@ See the [Plotly FigureWidget Overview](https://plot.ly/python/figurewidget/) for
251
251
It is important to note that `FigureWidget` does not use the renderers framework discussed above, so you should not use the `show()` figure method or the `plotly.io.show` function on `FigureWidget` objects.
252
252
253
253
254
-
## Rendering Performance
254
+
## Performance
255
255
256
-
No matter the approach chosen to display a figure (including HTML and static image export),
256
+
No matter the approach chosen to display a figure, [the figure data structure](https://plotly.com/python/figure-structure/) is first (automatically, internally) serialized into a JSON string before being transferred from the Python context to the browser (or [to an HTML file first](https://plotly.com/python/interactive-html-export/) or [to Kaleido for static image export](https://plotly.com/python/static-image-export/)).
257
+
258
+
The default JSON serialization mechanism can be slow for figures with many data points or with large `numpy` arrays or data frames. **If [the `orjson` package](https://github.com/ijl/orjson) is installed**, `plotly` will use that instead of the built-in `json` package, which can lead to **5-10x** speedups for large figures.
259
+
260
+
Once a figure is serialized to JSON, it must be rendered by a browser, either immediately in the user's browser, at some later point if the figure is exported to HTML, or immediately in Kaleido's internal headless browser for static image export. Rendering time is generally proportional to the total number of data points in the figure, the number of traces and the number of subplots. In situations where rendering performance is slow, we recommend considering [the use of `plotly` WebGL traces](/python/webgl-vs-svg/) to exploit GPU-accelerated rendering in the browser, or [using the Datashader library to do Python-side rendering](/python/datashader/) before using `px.imshow()` to render the figure.
Copy file name to clipboardExpand all lines: doc/python/webgl-vs-svg.md
+32-11
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ jupyter:
22
22
pygments_lexer: ipython3
23
23
version: 3.6.5
24
24
plotly:
25
-
description: Implement WebGL for increased speed, improved interactivity, and
25
+
description: Using WebGL for increased speed, improved interactivity, and
26
26
the ability to plot even more data!
27
27
display_as: basic
28
28
language: python
@@ -31,20 +31,40 @@ jupyter:
31
31
order: 14
32
32
permalink: python/webgl-vs-svg/
33
33
thumbnail: thumbnail/webgl.jpg
34
+
redirect_from: python/compare-webgl-svg/
34
35
---
35
36
36
-
Here we show that it is possible to represent millions of points with WebGL.
37
+
### SVG and canvas/WebGL: two browser capabilities for rendering
38
+
39
+
`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:
40
+
41
+
* Accelerated versions of SVG trace types: `scattergl`, `scatterpolargl`, `heatmapgl`,
42
+
* High-performance multidimensional trace types: `splom`, or `parcoords`
WebGL is a powerful technology for accelerating computation but comes with some strict limitations:
49
+
50
+
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
51
+
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
52
+
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.**
53
+
4. Size limits: browsers impose hardware-dependent limits on the height and width of figures using WebGL
54
+
55
+
### WebGL for Scatter Performance
56
+
57
+
In the examples below we show that it is possible to represent up to around a million points with WebGL-enabled traces.
37
58
For larger datasets, or for a clearer visualization of the density of points,
38
59
it is also possible to use [datashader](/python/datashader/).
39
60
40
-
#### Compare WebGL and SVG
41
-
Checkout [this notebook](https://plotly.com/python/compare-webgl-svg) to compare WebGL and SVG scatter plots with 75,000 random data points
61
+
### WebGL with Plotly Express
42
62
43
-
#### WebGL with Plotly Express
63
+
The `rendermode` argument to supported Plotly Express functions (e.g. `scatter` and `scatter_polar`) can be used to enable WebGL rendering.
44
64
45
-
The `rendermode`argument to supported Plotly Express functions can be used to enable WebGL rendering.
65
+
> **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.
46
66
47
-
Here is an example that creates a 100,000 point scatter plot using Plotly Express with WebGL rendering enabled.
67
+
Here is an example that creates a 100,000 point scatter plot using Plotly Express with WebGL rendering explicitly enabled.
The `Scattergl` trace type can be used to create a WebGL enabled scatter plot.
89
+
#### WebGL with 100,000 points with Graph Objects
90
+
91
+
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/).
71
92
72
93
```python
73
94
import plotly.graph_objects as go
@@ -95,7 +116,7 @@ fig.add_trace(
95
116
fig.show()
96
117
```
97
118
98
-
#### WebGL with 1 Million Points
119
+
#### WebGL Rendering with 1 Million Points
99
120
100
121
```python
101
122
import plotly.graph_objects as go
@@ -149,4 +170,4 @@ fig.show()
149
170
150
171
### Reference
151
172
152
-
See https://plotly.com/python/reference/scattergl/ for more information and chart attribute options!
173
+
See https://plotly.com/python/reference/scattergl/ for more information and chart attribute options!
0 commit comments