Exporting Graphs
After generating our visualizations and configuring the details, we can export our graphs to a hard copy format, such as PNG, JPEG, or SVG. If we are using the interactive API in the notebook, we can just call the savefig function over the pyplot interface, and the last generated graph will be exported to the file:
df.plot(kind='scatter', x='weight', y='horsepower', figsize=(20,10)) plt.savefig('horsepower_weight_scatter.png')
All plot configurations will be carried to the plot. To export a graph when using the object-oriented API, we can call savefig from the figure:
fig, ax = plt.subplots() df.plot(kind='scatter', x='weight', y='horsepower', figsize=(20,10), ax=ax) fig.savefig('horsepower_weight_scatter.jpg')
We can change some parameters for the saved image:
dpi: Adjust the saved image resolution.
facecolor: The face color of the figure.
edgecolor: The edge color of the figure, around the graph.
format: Usually PNG...