How to remove lines in a Matplotlib plot

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

    (using the same example as the guy above)

    from matplotlib import pyplot
    import numpy
    a = numpy.arange(int(1e3))
    fig = pyplot.Figure()
    ax  = fig.add_subplot(1, 1, 1)
    lines = ax.plot(a)
    
    for i, line in enumerate(ax.lines):
        ax.lines.pop(i)
        line.remove()
    

提交回复
热议问题