Automargins cause imshow figure to jump around and change pixel size and labels spacing
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- python
研究方向
從提供的 Python px.imshow 重現開始,將 automargin=True 與手動邊界解決方案進行比較,並檢查 x 軸和 y 軸的 automargin 行為。追蹤 update_xaxes 和 update_yaxes 所使用的 automargin 計算或套用方式。當不同大小的熱圖無需手動邊界即可維持一致的像素大小、位置和標籤間距時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
I wasn't sure if this was a bug initially so I provided a reproducible example and closer description in the forum.
Briefly, with automargin=False, heatmaps of different figure sizes have the same pixel size:

Setting automargin=True creates figures with widely different pixel sizes and shifts where the figure appear and its whitespace (with more than just the label length):

The jumping around behavior and inconsistent pixel sizes both seem to come from a bug in how the automargins are calculated or applied. A workaround is to set automargin=False and then manually specifying how much space is needed for the labels in the margin dictionary, e.g. margin=dict(t=100, b=0, l=80, r=0) and pad the overall figure size with these numbers, e.g. height = 100 + cut * 30.
It seems like the automargins are not correctly adding their label padding to the overall figure size, so that would be my suggestion for what could be a possible solution here.
Example code:
import plotly.express as px
import numpy as np
import pandas as pd
np.random.seed(20934)
img = np.random.rand(200, 200)
for cut in [10, 50]:
fig = px.imshow(
img[:cut, :cut],
height=cut * 30,
width=cut * 30,
x = [''.join(np.random.choice(list('qwertyuioplkjhgfdsazxcvbnm,.;[098765432'), np.random.choice(40))) for x in range(cut)],
y = [''.join(np.random.choice(list('qwertyuioplkjhgfdsazxcvbnm,.;[098765432'), np.random.choice(40))) for x in range(cut)],
)
fig.update_layout(
coloraxis_showscale=False,
margin=dict(t=0, b=0, l=0, r=0),
xaxis_nticks=cut + 1,
yaxis_nticks=cut + 1,
).update_xaxes(
automargin=False,
).update_yaxes(
automargin=False,
)
fig.show()
- 主要語言
- Python
- 星號
- 18.8k
- 分支
- 2.8k
- 平均合併
- 16 小時 26 分鐘
- 30 天內合併 PR
- 21
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
plotly/plotly.py 的其他 Issue
-
P3 size: 1 task
難度 2/5 1-3 小時 新手友好度 72/100
-
bug P1
難度 1/5 1 小時以內 新手友好度 68/100
-
feature P3
難度 2/5 1-3 小時 新手友好度 62/100
-
feature P3
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 3/5 1-2 天 新手友好度 35/100
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 74/100
bancolombia/sentinel#23 ·
-
test md 未關閉CI
難度 2/5 1-3 小時 新手友好度 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
難度 2/5 1-3 小時 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
bug client
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 74/100