Garbage collect pyplot figures generated from `gopen`/`gclose`
Nobody has claimed this yet.
Assessment
This issue has not been assessed yet.
Description
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.
- Dominant language
- Python
- Stars
- 21
- Forks
- 11
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NCAS-CMS/cf-plot
-
Add badges to READMEOpendocs
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
dependencies infrastructure installation testing
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 3/5 Half a day Newbie friendliness 45/100
-
`title` not showing for `con` with certain projectionsPossibly taken @sadielbartholomew claimed this 1 day ago. Openbug plotting
All issues in NCAS-CMS/cf-plot
Similar issues
-
Server mode OAuth2: 'NoneType' object is not subscriptable on every request after re-submitting the OAuth2 login while already logged inPossibly taken @Rarasinhoo claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
pgadmin-org/pgadmin4#10733 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
aws-samples/sample-per-model-bedrock#752 ·
Maintainers usually reply within 1 day
-
lesson-submission pending-review
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Ikalus1988/MisakaNet#4452 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OCHA-DAP/topo-tools#250 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day