jupyter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Here we show that it is possible to represent millions of points with WebGL. For larger datasets, or for a clearer visualization of the density of points, it is also possible to use datashader.
Checkout this notebook to compare WebGL and SVG scatter plots with 75,000 random data points
The rendermode
argument to supported Plotly Express functions can be used to enable WebGL rendering.
Here is an example that creates a 100,000 point scatter plot using Plotly Express with WebGL rendering enabled.
import plotly.express as px
import pandas as pd
import numpy as np
np.random.seed(1)
N = 100000
df = pd.DataFrame(dict(x=np.random.randn(N),
y=np.random.randn(N)))
fig = px.scatter(df, x="x", y="y", render_mode='webgl')
fig.update_traces(marker_line=dict(width=1, color='DarkSlateGray'))
fig.show()
The Scattergl
trace type can be used to create a WebGL enabled scatter plot.
import plotly.graph_objects as go
import numpy as np
N = 100000
# Create figure
fig = go.Figure()
fig.add_trace(
go.Scattergl(
x = np.random.randn(N),
y = np.random.randn(N),
mode = 'markers',
marker = dict(
line = dict(
width = 1,
color = 'DarkSlateGrey')
)
)
)
fig.show()
import plotly.graph_objects as go
import numpy as np
N = 1000000
# Create figure
fig = go.Figure()
fig.add_trace(
go.Scattergl(
x = np.random.randn(N),
y = np.random.randn(N),
mode = 'markers',
marker = dict(
line = dict(
width = 1,
color = 'DarkSlateGrey')
)
)
)
fig.show()
import plotly.graph_objects as go
import numpy as np
fig = go.Figure()
trace_num = 10
point_num = 5000
for i in range(trace_num):
fig.add_trace(
go.Scattergl(
x = np.linspace(0, 1, point_num),
y = np.random.randn(point_num)+(i*5)
)
)
fig.update_layout(showlegend=False)
fig.show()
See https://plotly.com/python/reference/#scattergl for more information and chart attribute options!