Hello,
I have a Qt4 application with dynamic embedded matplotlib plotting.
The application allows the user to add and remove lines from the plot.
This all works well, but I have found that updating the legend is
causing a memory leak. What is the proper way to update the legend in
an animated/dynamic context? The attached stand alone example
exemplifies the problem. On my system, with matplotlib.__version__
'1.0.0' compiled from SVN, the memory slowly increases as the script
runs. This does not happen if I remove the ax.legend() call. The del
ax.legend_ line seems to have no effect. I tried finding the artists
associated with the legend What's the appropriate way to update the
legend to avoid this behavior? I just found ax.legend_.remove() but it
raises NotImplementedError

Thanks,
Glenn
import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
import numpy as np

f = plt.figure()
ax = f.add_subplot(111)

l, = ax.plot(np.arange(100),np.random.randn(100),label='hi',animated=True)
ax.legend()
print "press enter to start"
raw_input()

for k in range(10000):
    l.set_ydata(np.random.randn(100))
    del ax.legend_
    ax.legend() #prop = matplotlib.font_manager.FontProperties(size='small'))
    f.canvas.draw()
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to