0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

matplotlib "UserWarning: FigureCanvasAgg is non-interactive" 対処法

Last updated at Posted at 2025-07-26

概要

Ubuntu 22.04の仮想環境(venv)でmatplotlibを使っていたところ、plt.show() でグラフが表示されず、以下のような警告が出た。

UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown

これはPyQt5をインストールすることで解決した。
この記事ではそのとき調べたことをまとめる。

問題

matplotlibには複数のバックエンドがある。
バックエンドとは、描画をどの方法で行うかを決定する仕組みのこと。
バックエンドには、ウィンドウ表示ができるもの(インタラクティブなもの)とできないもの(非インタラクティブなもの)がある。

matplotlibは起動時に利用可能なGUIライブラリを探して、自動的に使えるバックエンドを選択する。
インタラクティブな表示を可能にするためには、GUIライブラリを仮想環境にインストールする必要があった。

解決方法

PyQt5をインストールした。

pip install pyqt5

他にもTkinter(python3-tk)などでもうまくいくはず。
PyQt5やTkinterなどのGUIライブラリがインストールされていれば、matplotlibが自動で選んでくれる。
今回はqtaggを自動で選んでくれるようになった。

確認方法

現在のバックエンドは以下のようにして確認できる。

import matplotlib
print(matplotlib.get_backend())

まとめ

matplotlibでグラフが表示されない場合はまずバックエンドを疑う。
同じ問題に直面した方の参考になれば幸いです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?