LoginSignup
1
0

More than 1 year has passed since last update.

Fail to create pixmap with Tk_GetPixmap in TkImgPhotoInstanceSetSize

Posted at

概要

下記の様なコードでメモリエラーが出ました。

sample.py
import matplotlib
import matplotlib.pyplot as plt

#グラフループ
for i in range(1000):
    #グラフオブジェクト
    fig, ax = plt.subplots()
    #描画
    ax.plot(x,y)
    #出力
    fig.savefig(path_file)
    #図形クリア
    plt.clf()
    #window閉じる
    plt.close()

エラー内容

Fail to create pixmap with Tk_GetPixmap in TkImgPhotoInstanceSetSize

原因

fig.savefigが原因の様です。

解決方法

matplotlib.use('Agg') を追記して、解決しました。

sample.py
import matplotlib
import matplotlib.pyplot as plt

#
matplotlib.use('Agg')  #追記

#グラフループ
for i in range(1000):
    #グラフオブジェクト
    fig, ax = plt.subplots()
    #描画
    ax.plot(x,y)
    #出力
    fig.savefig(path_file)
    #図形クリア
    plt.clf()
    #window閉じる
    plt.close()

参照
plt.close() だけではメモリが解放されない場合がある

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