Layout images disappear in odd cases
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 18.3k
- Fork
- 2k
- Merge trung bình
- 2 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 28
Mô tả
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 bysizexandsizey, 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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với bản tái hiện plotly.js được cung cấp bằng cách sử dụng add_layout_image, tập trung vào các hình ảnh layout tham chiếu đến các trục dữ liệu x/y, các giá trị sizex/sizey cực lớn và các tọa độ số trên trục ngày tháng. Được xem là hoàn thành khi hình ảnh vẫn hiển thị với kích thước rất lớn và khi các giá trị ngày tháng được cung cấp dưới dạng số nguyên, phù hợp với hành vi được mô tả cho các năm dạng chuỗi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100