<Python, matplotlib, pyplot> Figureを作りすぎで怒られた場合。

fig, ax =plt.subplots()をループするスクリプトを作ったら、次のエラーで怒られた。

/hoge/python/lib/python3.4/site-packages/matplotlib/pyplot.py:424: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

作りすぎでメモリ食い杉。

Figureを消すには、plt.clf() らしい。

マニュアル。
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.clf

stackoverflow。
matplotlib: clearing a plot, when to use cla(), clf() or close()? - Stack Overflow