Get the list of figures in matplotlib

前端 未结 6 2591
南旧
南旧 2020-11-30 01:36

I would like to:

pylab.figure()
pylab.plot(x)
pylab.figure()
pylab.plot(y)
# ...
for i, figure in enumerate(pylab.MagicFunctionReturnsListOfAllFigures()):
           


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 02:12

    Pyplot has get_fignums method that returns a list of figure numbers. This should do what you want:

    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.arange(100)
    y = -x
    
    plt.figure()
    plt.plot(x)
    plt.figure()
    plt.plot(y)
    
    for i in plt.get_fignums():
        plt.figure(i)
        plt.savefig('figure%d.png' % i)
    

提交回复
热议问题