matplotlib / matplotlib/matplotlib

[Bug]: Axes.cla() with sharex may wrongly reset the axes limit.

Aperta
#27,825 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

topic: axes
Lingua principale
Python
Stelle
23.2k
Fork
8.5k
Merge medio
1g 6h
PR unite (30g)
66

Descrizione

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

image

Expected outcome

image

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.