How to remove lines in a Matplotlib plot

前端 未结 5 1936
忘掉有多难
忘掉有多难 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:12

    Hopefully this can help others: The above examples use ax.lines. With more recent mpl (3.3.1), there is ax.get_lines(). This bypasses the need for calling ax.lines=[]

    for line in ax.get_lines(): # ax.lines:
        line.remove()
    # ax.lines=[] # needed to complete removal when using ax.lines
    

提交回复
热议问题