-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
bugsomething brokensomething broken
Description
When I do a scattergl interactive plot with too many points the points disappear and the following error is output.
Reproducible example
import plotly.offline as py # 3.7.1
import plotly.graph_objs as go
import datashader as ds # 0.6.9
import numpy as np
import pandas as pd
def ds_image_to_data(x_range, y_range, plot_width, plot_height):
if x_range is None or y_range is None or plot_width is None or plot_height is None:
return None
cvs = ds.Canvas(x_range=x_range, y_range=y_range, plot_height=plot_height, plot_width=plot_width)
agg_scatter = cvs.points(df, 'x', 'y', ds.any())
# get a boolean pixel mapping with index x and columns y
agg_scatter = agg_scatter.to_pandas().transpose()
# get a dataframe with columns x, y and boolean for pixel state
agg_scatter = agg_scatter.stack().reset_index()
# get only values with pixel set to True
agg_scatter = agg_scatter.loc[agg_scatter[agg_scatter.columns[2]]]
print(f'Plotting {len(agg_scatter)} points')
return agg_scatter['x'], agg_scatter['y']
def update_layout(layout, x_range, y_range, plot_width, plot_height):
# Update with batch_update so all updates happen simultaneously
with fig.batch_update():
fig.layout.xaxis.range = (x_range[0], x_range[-1])
fig.layout.yaxis.range = (y_range[0], y_range[-1])
fig.data[0].x, fig.data[0].y = ds_image_to_data(x_range, y_range, plot_width, plot_height)
size = 100000
df = pd.DataFrame({'x': np.arange(0, size),
'y': np.sin(np.arange(0, size))})
x_range=[df.x.min(), df.x.max()]
y_range=[df.y.min(), df.y.max()]
plot_height=400
plot_width=800
trace = go.Scattergl(
x = df['x'],
y = df['y'],
mode = 'markers',
)
layout = {'width': plot_width, 'height': plot_height,
'xaxis': {'range': x_range},
'yaxis': {'range': y_range}
}
fig = go.FigureWidget(data=[trace], layout=layout)
fig.layout.on_change(update_layout, 'xaxis.range', 'yaxis.range', 'width', 'height')
figYou can check the relecant plotly community discussion here: https://community.plot.ly/t/scattergl-points-disappear-on-figurewidget-update/21100
Metadata
Metadata
Assignees
Labels
bugsomething brokensomething broken
