matplotlib / matplotlib/matplotlib
[Bug]: `ax.transData` does not honor data limits
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 23.2k
- 分支
- 8.5k
- 平均合併
- 1 天 6 小時
- 30 天內合併 PR
- 66
描述
Bug summary
ax.transData does not honor xlim and ylim. The document at https://matplotlib.org/stable/users/explain/artists/transforms_tutorial.html#data-coordinates seems to suggest that data limits are updated automatically when new data are added to the axes, but it's not the case, which breaks ax.transData, since it reads an old version of data limits.
Code for reproduction
from matplotlib import pyplot as plt
fig, ax = plt.subplots(figsize=(10, 10), dpi=100)
print(f"fig size: {fig.get_size_inches() * fig.dpi}")
ax.plot([0, 10], [0, 10], 'o')
print(f"(10, 10) in data coordinates: {ax.transData.transform((10, 10))}")
ax.set_xlim(ax.get_xlim()) # just ax.get_xlim() or ax.viewLim or ax.autoscale_view() is enough
ax.set_ylim(ax.get_ylim())
print(f"(10, 10) in data coordinates: {ax.transData.transform((10, 10))}")
Actual outcome
fig size: [1000. 1000.]
(10, 10) in data coordinates: [7875. 7810.]
(10, 10) in data coordinates: [864.77272727 845. ]
Expected outcome
fig size: [1000. 1000.]
(10, 10) in data coordinates: [864.77272727 845. ]
(10, 10) in data coordinates: [864.77272727 845. ]
Additional information
The wording from https://matplotlib.org/stable/users/explain/artists/transforms_tutorial.html#data-coordinates suggests that data limits are updated automatically when new data are added, but it requires manual trigger of set_xlim/set_ylim (or get_xlim/get_ylim which calls ax.viewLim).
This is quite confusing. I would hope that either the documentation is updated to notify the user to explicitly update the data limits, or even better, let transData/transLimits always use the latest data limits.
Operating system
No response
Matplotlib Version
3.8.3
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
重現提供的程式碼片段,然後檢查 transData/transLimits 的更新路徑以及連結的 data-coordinates 文件。確定解決方案是程式碼變更還是文件釐清,並在完成所選變更後驗證範例的座標輸出。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- data-visualization
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100