python
runtime_error
ai_generated
true
UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
ID: python/matplotlib-no-display-figure
80%Fix Rate
87%Confidence
0Evidence
2024-05-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
plt.show() called while matplotlib is using a non-interactive backend (Agg), typically on a headless environment or after matplotlib.use('Agg').
generic中文
在 matplotlib 使用非交互后端 (Agg) 时调用了 plt.show(),通常发生在无头环境或调用了 matplotlib.use('Agg') 之后。
Workarounds
-
97% success
fig, ax = plt.subplots() ax.plot([1,2,3]) fig.savefig('plot.png', dpi=150) -
82% success
pip install PyQt5 import matplotlib matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt plt.plot([1,2,3]); plt.show()
Dead Ends
Common approaches that don't work:
-
90% fail
The block argument only controls blocking behavior for interactive backends; Agg still cannot render a window.
-
85% fail
The backend selection is environment-driven, not an installation defect.