Edinburgh-Genome-Foundry / DnaFeaturesViewer

:eye: Python library to plot DNA sequence features (e.g. from Genbank files)
https://edinburgh-genome-foundry.github.io/DnaFeaturesViewer/
MIT License
584 stars 90 forks source link

How to solve the memory problem of batch plotting? #78

Closed brilliantlee2 closed 1 year ago

brilliantlee2 commented 1 year ago

Hi! Thanks for your package! I have a problem recently, when I plot linear genomes in batches, the memory usage is too high, how to solve this problem? What I found can be solved with commands like plt.clf(). How can I do it in this package? Thank you for your answer!

brilliantlee2 commented 1 year ago

The warning like: home/anaconda/envs/DFV/lib/python3.9/site-packages/dna_features_viewer/GraphicRecord/MatplotlibPlottableMixin.py:438: 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(). fig, ax = plt.subplots(1, figsize=(figure_width, height))

veghp commented 1 year ago

It's not clear if the issue is within the package (that is, it opens a lot of plots but doesn't close them), or your script. Assuming it's your script issuing batch plot commands, see https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/blob/master/examples/example_with_gif.py#L49 for an example on how plt.close is used. (plt = matplotlib.pyplot)

brilliantlee2 commented 1 year ago

Thanks for your anwser, I solved this problem just add plt.close(ax.figure) after ax, _ = record.plot(figure_width=10)