Saving graphs as images

If I want to save this graph to a file, maybe I want to include it in a document or something, I can do something like the following code:

plt.plot(x, norm.pdf(x)) 
plt.plot(x, norm.pdf(x, 1.0, 0.5)) 
plt.savefig('C:\Users\Frank\MyPlot.png', format='png') 

Instead of just calling plt.show(), I can call plt.savefig() with a path to where I want to save this file and what format I want it in.

You'll want to change that to an actual path that exists on your machine if you're following along. You probably don't have a UsersFrank folder on your system. Remember too that if you're on Linux or macOS, instead of a backslash you're going to use forward slashes, and you're not going to have a drive letter. With all of these Python Notebooks, whenever you see a path like this, make sure that you change it to an actual path that works on your system. I am on Windows here, and I do have a UsersFrank folder, so I can go ahead and run that. If I check my file system under UsersFrank, I have a MyPlot.png file that I can open up and look at, and I can use that in whatever document I want.

That's pretty cool. One other quick thing to note is that depending on your setup, you may have permissions issues when you come to save the file. You'll just need to find the folder that works for you. On Windows, your UsersName folder is usually a safe bet. Alright, let's move on.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.66.132