matplotlib / matplotlib/matplotlib

[Bug]: mpl.style.context() stops plotting inline in Jupyter

Offen
#26,716 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

topic: backends
Vorherrschende Sprache
Python
Sterne
23.2k
Forks
8.5k
Ø Merge
1 T. 6 Std.
Gemergte PRs (30 T.)
66

Beschreibung

### Bug summary

Under certain circumstances, when using matplotlib.style.context() to temporarily alter the default style in a Jupyter notebook, it resets the backend to no plot inline. This occurs if the plot is the first one in the notebook, but not if another plot (without the context manager) has already been plotted.

### Code for reproduction

```python
# CASE 1:
# first cell - produces inline plot with desired grid
import matplotlibl.pyplot as pl

with plt.style.context({'axes.grid': True}):
plt.plot(range(10))

# second cell - does not produce in line plot
plt.plot(range(10))

# CASE 2:
# first cell - produces inline plot
import matplotlibl.pyplot as plt
plt.plot(range(10))

# second cell - produces inline plot with desired grid
with plt.style.context({'axes.grid': True}):
plt.plot(range(10))

# third cell - produces in line plot
plt.plot(range(10))
```

### Actual outcome

CASE 1:
![image](https://github.com/matplotlib/matplotlib/assets/143531681/d885aa2b-9f65-4df3-afcb-485cae9b2714)

CASE 2:
![image](https://github.com/matplotlib/matplotlib/assets/143531681/b82b505e-4629-4ba0-b2a1-06cbf8012665)

### Expected outcome

In case 1, the second plot should be inline

### Additional information

_No response_

### Operating system

Windows 10.0.19045 Build 19045

### Matplotlib Version

3.7.2

### Matplotlib Backend

'module://matplotlib_inline.backend_inline'

### Python version

3.10.10

### Jupyter version

6.4.12

### Installation

pip

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere die beiden Fälle in einem Jupyter-Notebook mit den angegebenen Versionen von Matplotlib, Python und dem Inline-Backend. Beginne bei matplotlib.style.context() und seiner Interaktion mit module://matplotlib_inline.backend_inline; abgeschlossen ist die Aufgabe, wenn der zweite Plot in Fall 1 inline bleibt und ein Regressionstest die Sequenz abdeckt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
jupyter, python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.