Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Garbage collect pyplot figures generated from `gopen`/`gclose`

オープン
#87 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

@sadielbartholomew がすでに取り組んでいます。

2025年3月24日 から。

評価

この issue はまだ評価されていません。

説明

Figures created using plotting functions wrapped with gopen and gclose functions to produce them on a single graphics file are not properly closed, such that they remain in memory and cause inefficiency. This is demonstrated by the warning produced when ~10-20 of these are opened from one script, for example as a quick contrived means to produce it through a loop such as:

>>> f = cf.read('cfplot_data/tas_A1.nc')[0]
>>> for _ in range(20):
...     cfp.gopen()
...     cfp.con(f.subspace(time=15))
...     cfp.gclose()
... 
/home/slb93/git-repos/cf-plot/cfplot/cfplot.py:6244: 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`). Consider using `matplotlib.pyplot.close()`.
  plotvars.master_plot = plot.figure(figsize=(figsize[0], figsize[1]))

We should apply proper garbage collection by closing any figures through matplotlib.pyplot.close() (as advised by the warning), or otherwise. We could consider a means to not close these until the user explicitly instructs to, in case they want to recover a previous plot, but since there doesn't appear to be any functionality in cf-plot to recover a plot once gclose is called anyway (i.e. the plot file saved to disk is the only product/remnant), this would first require further functionality to fetch a previous result.

主要言語
Python
スター
21
フォーク
11
平均マージ
7時間 11分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NCAS-CMS/cf-plot のほかの issue

NCAS-CMS/cf-plot の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。