How to remove lines in a Matplotlib plot

前端 未结 5 1948
忘掉有多难
忘掉有多难 2020-11-27 12:51

How can I remove a line (or lines) of a matplotlib axes in such a way as it actually gets garbage collected and releases the memory back? The below code appears to delete t

5条回答
  •  广开言路
    2020-11-27 13:08

    I've tried lots of different answers in different forums. I guess it depends on the machine your developing. But I haved used the statement

    ax.lines = []
    

    and works perfectly. I don't use cla() cause it deletes all the definitions I've made to the plot

    Ex.

    pylab.setp(_self.ax.get_yticklabels(), fontsize=8)
    

    but I've tried deleting the lines many times. Also using the weakref library to check the reference to that line while I was deleting but nothing worked for me.

    Hope this works for someone else =D

提交回复
热议问题