matplotlib / matplotlib/matplotlib
[Bug]: mpl.style.context() stops plotting inline in Jupyter
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
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:

CASE 2:

### 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
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
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