Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Let's see how easy matplotlib makes it to save our charts for publication to the web and other publication formats.
Further Reading
- Matplotlib figure() method
- Matplotlib backend
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
So far we've just been displaying
our charts to the screen.
0:00
As I mentioned earlier in the course,
0:03
one of the Matplotlib's strengths is
producing the publication ready images.
0:05
Let's see how we can save some
visualizations of our Iris data, so
0:09
we can share our results with others.
0:13
Let's use our box plot code here as
an example to generate our files.
0:15
To save files, we need to utilize matplotlib's
figure object and save fig method.
0:19
Like I mentioned, we assigned a
variable, fig, to plt.figure.
0:26
We come in here, plt.figure.
0:31
And then down here at the bottom.
0:39
savefig, and
we pass in a file name for our chart.
0:45
We'll call it petal_length_boxplot.png.
0:50
We can run this out.
0:58
This is pretty cool.
1:08
We can see if we go over here
into our folder, and there it is.
1:10
Our petal_length_boxplot.png
file was created, now,
1:15
in this example, we generated the PNG
file which is great for websites.
1:19
Let's jump back over to our notebook and
see what other file types are supported.
1:23
Let's do a new cell.
1:30
So we import matplotlib.pyplot as plt.
1:33
Send our figure object, and
1:46
then if we print out
canvas.get_supported_filetypes.
1:50
And run our cell.
2:00
As you can see, there's support for
a lot of different file types or
2:04
in matplotlib language hard copy or
non-interactive back ends.
2:08
These handle most printed or
static display needs.
2:13
While it is beyond the scope of this
course, there are also user interface or
2:17
interactive back end options too.
2:22
I'll put a link in the teacher's notes for
resources on those.
2:25
This approach for
2:28
finding supported file types works
outside of jupyter notebooks too.
2:29
In case you want to use matplotlib's
power in a different environment.
2:32
We've covered a bunch
of stuff in this stage.
2:37
We explored our Iris Dataset
in several ways,
2:39
used several different visualization
tools and techniques, and
2:42
learned how to leverage matplotlib
to find patterns in data.
2:46
Data visualization is a fundamental
aspect of many job roles today.
2:49
For both data experts and
non-experts alike.
2:54
You're well on your way to
communicating information and
2:57
generating useful visualizations.
2:59
When we get back together,
let's move on to a different data set and
3:03
answer some specific business decision
questions with our new data viz skills.
3:06
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up