Save plot to image file instead of displaying it using Matplotlib

前端 未结 20 1746
一生所求
一生所求 2020-11-22 06:07

I am writing a quick-and-dirty script to generate plots on the fly. I am using the code below (from Matplotlib documentation) as a starting point:

from pylab         


        
20条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 06:38

    As suggested before, you can either use:

    import matplotlib.pyplot as plt
    plt.savefig("myfig.png")
    

    For saving whatever IPhython image that you are displaying. Or on a different note (looking from a different angle), if you ever get to work with open cv, or if you have open cv imported, you can go for:

    import cv2

    cv2.imwrite("myfig.png",image)

    But this is just in case if you need to work with Open CV. Otherwise plt.savefig() should be sufficient.

提交回复
热议问题