Show Sidebar Hide Sidebar

WebGL vs SVG in Python

Implement WebGL for increased speed, improved interactivity, and the ability to plot even more data!

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!!

Compare WebGL and SVG

Checkout this notebook to compare WebGL and SVG scatter plots with 75,000 random data points

WebGL with 100,000 points

In [1]:
import plotly.plotly as py
import plotly.graph_objs as go

import numpy as np

N = 100000
trace = go.Scattergl(
    x = np.random.randn(N),
    y = np.random.randn(N),
    mode = 'markers',
    marker = dict(
        line = dict(
            width = 1,
            color = '#404040')
    )
)
data = [trace]
py.iplot(data, filename='WebGL100000')
Out[1]:

WebGL with 1 Million Points

In [2]:
import plotly.plotly as py
import plotly.graph_objs as go

import numpy as np

N = 1000000
trace = go.Scattergl(
    x = np.random.randn(N),
    y = np.random.randn(N),
    mode = 'markers',
    marker = dict(
        color = 'rgb(152, 0, 0)',
        line = dict(
            width = 1,
            color = 'rgb(0,0,0)')
    )
)
data = [trace]
py.iplot(data, filename='WebGLmillion')
Out[2]:

WebGL with many traces

In [3]:
import plotly.plotly as py
import plotly.graph_objs as go

import numpy as np

data = []
trace_num = 10
point_num = 5000
for i in range(trace_num):
    data.append(go.Scattergl(
        x = np.linspace(0, 1, point_num),
        y = np.random.randn(point_num)+(i*5)
    )
)
layout = dict(showlegend=False)
fig=dict(data=data, layout=layout)
py.iplot(fig, filename='WebGL_line')
Out[3]:

Reference

See https://plot.ly/python/reference/#scattergl for more information and chart attribute options!

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.