There are many different ways to use matplotlib. The way that I recommend you get started is with Jupyter notebook, and interactive console that allows you to quickly see the output of all of your commands, whether it is text, a pandas data frame, or a matplotlib graph. Here is an example of a notebook in action. As you can see, they are great for telling a story, and keeping everything together in a cohesive narrative.
Why you would want to use savefig
However, it is also perfectly reasonable to run matplotlib in a script, and output the graphs as image files. For this purpose you will need the save fig function. This allows you to take the graph that you have been building, and out put it as an image file. This sounds simple, but there are a large number. Of several matplotlib configuration options that you need to keep in mind. The first is the number of dots per inch for DTI but you want your output image to have. This is important because it impacts the memory size of your image, and the amount of time that it takes to output. If you are spinning out a whole bunch of images, it can quickly grow overwhelming if you set your dpi too high. A rule of thumb standard is 300, but for small images going as low as 60 will do just fine. Trying to go up to 1000 or higher is really only recommended if you are putting just one or two images. Another decision you have to make is what filetype to use. By default, it will output a Png image. This is often a good choice, even though it doesn’t compress as well as JPG. You can also have savefig output a PDF, SVG, or any of a number of other file types. Note that if you want to output a PDF, there are better ways to do it, which give you much more control over that document overall.
Other factors for your visualization
Another factor to consider is what directory you want to write the image into. It often makes sense to create a custom directory just for storing your images. You will find if you skipped the things that you often I’ll put very many images, which can be overwhelming if it fits right alongside your code and working directory
Another consideration when you saving images is whether you were going to cut off important labels along the outer edges. Unfortunately, matplotlib doesn’t always do a perfect job about this, and you need to be careful that you are not accidentally leaving critical information out. You may need to shrink the image slightly before sending it, so that everything fits in the frame. One way to do this may be the BBOX argument.