matplotlib / matplotlib/matplotlib
[Bug]: Axes.cla() with sharex may wrongly reset the axes limit.
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 23.2k
- 派生
- 8.5k
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 66
描述
Bug summary
For example, when subplot A shares the x-axis with subplot B (A is created with sharex=B), a call to B.cla() will set the xlimit to [0, 1], which may not be expected (in contrast, a call to A.cla() will not change the xlimit).
I think the main problem comes from the following function, where it will check whether its _sharex attribute is None; however, in this case, B is shared to A, but no axis is shared to B, so B's _sharex attribute is None.
https://github.com/matplotlib/matplotlib/blob/9e18a343fb58a2978a8e27df03190ed21c61c343/lib/matplotlib/axes/_base.py#L1369
Code for reproduction
ax = plt.subplot(211)
ax2 = plt.subplot(212, sharex=ax)
ax.plot(range(50))
ax2.plot(range(50))
ax.cla()
plt.show()
Actual outcome
Expected outcome
Additional information
No response
Operating system
No response
Matplotlib Version
3.8.3
Matplotlib Backend
'TkAgg'
Python version
3.9.13
Jupyter version
No response
Installation
pip
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
阅读 lib/matplotlib/axes/_base.py 中链接的 Axes.cla() 代码,然后运行提供的、使用 sharex 的 subplot 复现。跟踪当 B 与 A 共享坐标轴时,共享坐标轴关系是如何表示的,并在不重置 x-limit 的情况下使行为符合预期结果。确认该复现不再意外更改 limit。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100