the active figure can be saved to file using plt savefig this method is equivalent to the figure object' savefig instance method for exampleto save an svg version of figureyou need only typeplt savefig('figpath svg'the file type is inferred from the file extension so if you used pdf instead you would get pdf there are couple of important options that use frequently for publishing graphicsdpiwhich controls the dots-per-inch resolutionand bbox_incheswhich can trim the whitespace around the actual figure to get the same plot as png above with minimal whitespace around the plot and at dpiyou would doplt savefig('figpath png'dpi= bbox_inches='tight'savefig doesn' have to write to diskit can also write to any file-like objectsuch as stringiofrom io import stringio buffer stringio(plt savefig(bufferplot_data buffer getvalue(for examplethis is useful for serving dynamically-generated images over the web table - figure savefig options argument description fname string containing filepath or python file-like object the figure format is inferred from the file extensione pdf for pdf or png for png dpi the figure resolution in dots per inchdefaults to out of the box but can be configured facecoloredge color the color of the figure background outside of the subplots ' (white)by default format the explicit file format to use ('png''pdf''svg''ps''eps'bbox_inches the portion of the figure to save if 'tightis passedwill attempt to trim the empty space around the figure matplotlib configuration matplotlib comes configured with color schemes and defaults that are geared primarily toward preparing figures for publication fortunatelynearly all of the default behavior can be customized via an extensive set of global parameters governing figure sizesubplot spacingcolorsfont sizesgrid stylesand so on there are two main ways to interact with the matplotlib configuration system the first is programmatically from python using the rc method for exampleto set the global default figure size to be you could enterplt rc('figure'figsize=( ) brief matplotlib api primer www it-ebooks info