plotly / plotly/plotly.js

Layout images disappear in odd cases

未关闭
#6,788 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P3 sev-3
主要语言
JavaScript
星标
18.3k
派生
2k
平均合并
2 天 12 小时
30 天内合并 PR
28

描述

Two situations where layout images referenced to data can disappear:

  • When one of the size parameters is far, far larger than necessary. Normally (with the default sizing: 'contain') the aspect ratio of the image is preserved, so in the rectangle described by sizex and sizey, one of those is limiting and the non-limiting size can be increased indefinitely with no visible effect. This has a limit though: if you make it something like a million times too big, the image abruptly disappears. (this one is from an example by @celia-plotly)
  • On a date axis, in data arrays integer numbers and integer strings are both treated as years, but in layout images only integer strings are treated as years; integer numbers are treated as milliseconds since 1970 (and with the local UTC offset no less 🤦)

Here's a working example:

import dash
from dash import dcc
import plotly.graph_objects as go
import pandas as pd

# Create a Dash app
app = dash.Dash(__name__)

df = pd.DataFrame.from_records([
    {"Year": 2008, "Tickets Sold": 8000000},
    {"Year": 2009, "Tickets Sold": 9000000},
    {"Year": 2010, "Tickets Sold": 5000000},
    {"Year": 2011, "Tickets Sold": 5000000},
    {"Year": 2012, "Tickets Sold": 7000000},
    {"Year": 2013, "Tickets Sold": 5000000},
    {"Year": 2014, "Tickets Sold": 7000000},
])
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Year"], y=df["Tickets Sold"]))
for j, row in df.iterrows():
    fig.add_layout_image(
        dict(
            source="https://upload.wikimedia.org/wikipedia/commons/8/8a/Plotly-logo.png",
            xref="x",
            yref="y",
            x=row["Year"],
            y=row["Tickets Sold"],
            sizex=1,
            sizey=1000000,
            xanchor="center",
            yanchor="middle",
        )
    )

# Define the app layout
app.layout = dcc.Graph(figure=fig, style={"height": "50vh"})

if __name__ == "__main__":
    app.run(debug=True)

And if you make sizex bigger, even as high as 10000, nothing changes. But go up to 100000 and the images disappear.

For the date flavor: add fig.update_xaxes(type="date") and sizex=1000*3600*24*365 (one year in msec), the images disappear. You can find them if you zoom out and back in around year 1970. But if you stringify, ie x=str(row["Year"]), they reappear atop the data points again.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 plotly.js 复现开始,使用 add_layout_image,重点关注引用 x/y 数据轴的布局图像、极端的 sizex/sizey 值,以及日期轴上的数值坐标。当图像在尺寸非常大时仍保持可见,并且在以整数形式提供日期值时表现与所描述的字符串年份行为一致,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。