Skip to content

How to prevent memory leaking while plotting? #731

Answered by KelSolaar
alban-sol asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @alban-sol,

It is very likely because Matplotlib does not close the figure automatically, try that:

import matplotlib.pyplot as plt
import colour

from colour import plotting
sample_sd_data = {
380: 0.048,
385: 0.051,
390: 0.055,
395: 0.060,
400: 0.065,
405: 0.075}
sd = colour.SpectralDistribution(sample_sd_data, name='Sample')

figure, axes = plotting.plot_single_sd(sd)
plt.close(figure)

Alternatively, you can also do that: plt.close(plotting.plot_single_sd(sd)[0])

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by KelSolaar
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #531 on January 16, 2021 22:53.