Learn

Wow, we covered a lot! Let’s export our finished line chart.

To export a chart, we just call the function plt.savefig(), giving the filename we want as an argument. So, to save a line chart as ‘my_lineplot.png’, we could simply call:

plt.savefig('my_lineplot.png')

Plots will default to .png format, but we can also specify the format as a parameter and save a plot as a .jpeg, .pdf, or .svg filetype, among others.

Two other helpful parameters are dpi and bbox_inches.

dpi allows us to set the resolution: the number of pixels in the image, or essentially, how big it is. This works the same whether the visualization is a square or a rectangle, which is convenient.

bbox_inches = 'tight' ensures that our legend, tick labels, and axes aren’t cut off. These elements exist outside the graph figure, but inside the bounding box or bbox.

The updated code looks like this:

plt.savefig('my_lineplot.png', dpi=128, bbox_inches='tight')

And that’s that – a line chart from start to finish!

Instructions

1.

Export your line chart as a .png file called line_chart.png.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?