Save plot to image file instead of displaying it using Matplotlib

前端 未结 20 1765
一生所求
一生所求 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条回答
  •  萌比男神i
    2020-11-22 06:47

    Additionally to those above, I added __file__ for the name so the picture and Python file get the same names. I also added few arguments to make It look better:

    # Saves a PNG file of the current graph to the folder and updates it every time
    # (nameOfimage, dpi=(sizeOfimage),Keeps_Labels_From_Disappearing)
    plt.savefig(__file__+".png",dpi=(250), bbox_inches='tight')
    # Hard coded name: './test.png'
    

提交回复
热议问题