pythonmatplotlibjupyter-notebook

saving figures using plt.savefig on colaboratory


I am using collaboratory(online jupyter notebook) I have the following code i am plotting some graphs using this functions and want to save plots locally how can I do this ?

def make_plot_comparison(Xlabel,Ylabel,l1,l2,l1_title,l2_title,name): 
    plt.xlabel(Xlabel)
    plt.ylabel(Ylabel)
    plt.plot(l1,label=l1_title)
    plt.plot(l2,label=l2_title)
    plt.legend(loc='center right')
    plt.title(name)
    #plt.xlim(-5, 25)
    plt.savefig("abc.png")
    plt.show()

Solution

  • maybe it can save the picture independently

    from google.colab import files
    plt.savefig("abc.png")
    files.download("abc.png") 
    

    https://colab.research.google.com/notebook#fileId=/v2/external/notebooks/io.ipynb&scrollTo=p2E4EKhCWEC5