matplotlib / matplotlib/matplotlib
[Bug]: Axes.cla() with sharex may wrongly reset the axes limit.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 23.2k
- Forks
- 8.5k
- Ø Merge
- 1 T. 6 Std.
- Gemergte PRs (30 T.)
- 66
Beschreibung
### 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
```Python
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Read lib/matplotlib/axes/_base.py at the linked Axes.cla() code, then run the supplied subplot reproduction with sharex. Trace how the shared-axis relationship is represented when B is shared to A, and make the behavior match the expected outcome without resetting the x-limit. Confirm the reproduction no longer changes the limit unexpectedly.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100