Scattergl points disappear when reaching a certain threshold in size difference
未关闭
还没有人认领这个 Issue。
bug
P3
sev-2
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
I noticed, that in Scattergl points start to disappear from the graph when resizing and reaching certain thresholds in size difference.
Minimal example:
from dash import Dash, html, dcc, callback
from dash.dependencies import Input, Output
import plotly.graph_objects as go
from plotly.graph_objs import Scattergl
import numpy as np
import pandas as pd
np.random.seed(41)
x = np.random.uniform(-10, 10, 10)
y = np.random.uniform(-10, 10, 10)
sizes = np.random.uniform(0, 1000, 10)
df = pd.DataFrame({
'x': x,
'y': y,
'sizes': sizes
})
app = Dash(__name__)
app.layout = html.Div([
dcc.Slider(min=13, max=14, value=1, id='slider-sizes', step=0.1),
dcc.Graph(id='graph', style={"width": "100vw", "height": "80vh"}),
])
def update_marker_sizes(fig, size):
for trace in fig.data:
if 'marker' in trace and 'size' in trace.marker:
trace.marker.size = [s * size for s in trace.marker.size]
return fig
@callback(
Output('graph', 'figure'),
Input('slider-sizes', 'value')
)
def update_graph(size):
figure = go.Figure(data=Scattergl(x=df["x"], y=df["y"], mode='markers',
marker=dict(size=df['sizes']*size, sizemode='area')))
print(f"{50*'-'}\nslider size:{size}")
num_points = sum(
len(trace['x']) for trace in figure.full_figure_for_development()['data'] if
len(trace["x"]) > 1)
print(f"num points in dev data (x): {num_points}")
minsize, maxsize = float("inf"), float("-inf")
for trace in figure.data:
if hasattr(trace, 'marker') and hasattr(trace.marker, 'size'):
if len(trace.marker.size) > 1:
print(f"num points in data: {len(trace.marker.size)}")
minsize = min(minsize, min(trace.marker.size))
maxsize = max(maxsize, max(trace.marker.size))
print(f"min: {minsize}, max: {maxsize}, diff: {maxsize - minsize}")
return figure
if __name__ == '__main__':
app.run_server(debug=True, port=8000)
The points are still present in the underlying data structure:
Output:
--------------------------------------------------
slider size:13.5
num points in dev data (x): 10
num points in data: 10
min: 1350.4235691765416, max: 10008.250444470288, diff: 8657.826875293747
--------------------------------------------------
slider size:13.6
num points in dev data (x): 10
num points in data: 10
min: 1360.4267067259975, max: 10082.385632947846, diff: 8721.958926221849
--------------------------------------------------
slider size:13.5
num points in dev data (x): 10
num points in data: 10
min: 1350.4235691765416, max: 10008.250444470288, diff: 8657.826875293747
--------------------------------------------------
Visually, this is what happens:
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行 issue 中的最小 Dash 示例,并在报告的尺寸阈值附近调整滑块。跟踪 Scattergl 的渲染路径,以确定为什么点会消失,尽管它们仍保留在数据中,然后验证在能够复现问题的整个尺寸范围内所有点都保持可见。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100