LoginSignup
1
1

More than 5 years have passed since last update.

Ubuntuで発生するmatplotlibのエラーの対処

Last updated at Posted at 2018-03-20

はじめに

Windowsで書いていたpyファイルをUbuntu上で動かそうとしたらエラーが出た。その対処法のメモ。

実行環境

Ubuntu 16.04 LTS
Python 3.6.3
matplotlib 2.2.2

事象

plt.showしていたWindowsで動かしていたpyファイルをUbuntu上(正確にはコンテナ上)で動かそうとしたら以下のエラーが発生。

_tkinter.TclError: no display name and no $DISPLAY environment variable

対処法

plt.showではなくplt.savefigにしてファイル保存しますがそれだけではダメで、
以下の手順が必要みたいです。

設定ファイル「matplotlibrc」を修正します。
まずpythonを起動してmatplotlibの設定ファイルの場所を確認。

import matplotlib as mpl
print(mpl.get_configdir())

/root/.config/matplotlib

ただし、おそらく上記の場所に「matplotlibrc」は存在しません。

/etc/matplotlibrc

があるため、vimで以下を修正する

backend : TkAgg

backend : Agg

その上で、「matplotlibrc」をコピー

cp /etc/matplotlibrc /root/.config/matplotlib/matplotlibrc 

これでOK。

参考

matplotlibで$DISPLAYが未定義の際に怒られた場合の対応
Matplotlibのグラフのスタイルを設定ファイル・スタイルシートで変更

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