So let's get started with map plot lib.
We're going to start on the desktop and do what we always do and hit the terminal.
Beautiful.
I'll zoom in a little bit on here.
Excellent.
Now we're going to go through a little workflow like we always do.
So we're going to see these for me and get into the sample project folder which contains our environment.
We can always see our environment by using Condit and list so this will show me my environments.
This is the one I'm after here.
Sample project the folder we've been working through before going to seed a I'm on the desktop right
now.
We can see that there.
So go into email course we can see that little folder up here but we're gonna use a command line and
then see it again into sample project.
Beautiful.
And then we can run content activate.
Now you could just copy and paste this and do that there.
But remember we're in the habit of typing out code.
That's a best habit you can develop that way you'll get used to writing things out for yourself and
practicing see what it feels like on your fingers to write code.
So if you conduct activate that should be all correct.
Wonderful.
And so we've had base change from this to this.
We've seen all this before.
I'm going to load up a tube but a notebook.
Our favorite workspace
we've got introduction to num pi pan is we've been through those we're gonna start a new one so now
we're going to retitle this one to be introduction to Matt bot lib.
Beautiful.
Well I have a title introduction to Matt pot lib.
Just so we know what's going on we're in the habit of communicating what we're doing.
There we go.
Beautiful.
And so now we're in a Jupiter notebook.
The first step for always using that plot lib is we might import naptime pandas as well so we import
all the tools we need right at the top of the notebook.
This is kind of a regular workflow.
So when first one order was Matt.
Plot lib in line.
Now if you've never seen this before.
This little percentage sign you might have in a previous video but this is a magic command.
So this percentage sign is telling Jupiter hey we want all of our map plot lib plots our graphs and
visualizations to appear within the notebook.
So that'll make more sense once we run it.
So let's import map plot lib dot pi plot.
Now pi plot is a python plotting module of map plot lib and the convenient name is as penalty will also
get pandas as PD and import num pi as MP and we'll hit shift enter.
This might take a little while depending on what's going on.
Beautiful.
So now we should have all these tools accessible now.
Simplest way to create a plot in map plot lib is with BLT dot plot.
So if we go shift tab I have a look at what this says.
Plot X vs. Y as lines and or markers.
What happens if we just run this huh.
Okay we'll get kind of that empty box that we saw before that was in the map plot lib workflow.
So this is how create a plot.
This is our figure that we've just created.
So we go back to our group a notebook.
This is our figure that we've just created.
But for some reason the output it's giving us these empty brackets so to get rid of those you can put
a semicolon at the end of your plot call.
So let's do that same thing.
We just don't have that nasty little output there.
This is what map plot they have in line means is that this plot is in the notebook so we can see it
visually right here.
That's all that plot Libyan line means.
If we didn't call this it would just output something like this with no plot.
So that's what this line of code is doing does the ideal scenario to always run that when you want to
run map properly it plots.
And now we didn't want to use the semicolon.
We wanted to be a bit more communicated.
We could go plot and then P L T dot show that's gonna do the exact same thing.
We got a nice and blank plot here.
Now how about we add some data so they go BLT dot plot and then hit shift tab.
Plot X vs. Y as lines and or markers and if we click the plus sign gives us a little example here of
plot x y.
So how about we pass it X as a list of some sort.
So maybe we'll just keep it nice and simple one two three four and we'll put the semicolon at the end
and see what happens.
Here we go.
We've got a line so this is on the x axis.
We should have one two three four.
Okay.
Beautiful.
So what can we try next.
Well let's create some x and y data x 1 2 3 four wonderful Y equals.
Let's mix it up a little bit.
11 twenty to thirty three forty four.
Wonderful.
Now let's see what these look like plot on plot x y and we put a semicolon at the end.
There we go.
We notice that our axes have changed so now we've gone from 1 to 4 on the X and from 11 to 44 on the
y.
Okay let's start a make a bit more sense.
This is looking good now this way of plotting and map plot lib is referred to as this stateless way
of plotting.
And if you've ever used Matlab it works like that but if you haven't used Matlab before not to worry
Let's have a quick look at that plot lib documentation because in there it tells us a little bit about
different types of plotting in map plot lib what do you want documentation to tall rails ply plot tutorials
so this is the type of plotting that we're using at the moment not map plot layer.
Pipeline is a collection of command style functions that make map plot layer work like matlab.
So we just went through each pie pop function make some change to a figure creates a figure.
So I've been calling these plots.
They're also referred to as figures creates a plotting area in the figure plot some lines in a plotting
area decorates the plot with labels etc. In my plot lived up high plot various states are preserved
across function calls.
Okay.
Where does reading the documentation here.
So this is the one we're paying attention to.
Note the pipeline API is generally less flexible than the object orientated API.
So remember how I said there's two ways of plotting in that plot lib.
Well we've just looked at the pipeline API and we're going to look at the object orientated API in a
second but this is a while we're gonna be focused on most the object orientated API because we want
as much flexibility as we can get right.
There's one more thing I want to show you.
So if we go map plot lib lifecycle plot the lifecycle of a plot.
There we go and you can get to this in the documentation as well.
So this is just map plot there.
Dot org tutorials lifecycle of a plot.
There we go.
This is the same thing in general trying to use the object orientated interface over the PI plot interface.
Okay so the documentation is saying these two things in bold notes we might listen to it right because
the people who write these documentation I really know what they're doing.
So let's see this is the first method will go fig Eagles now figure short for figure the LTE dot figure.
This creates a figure
axe is short for axes.
So remember this whole thing is a figure but these two lines here are axes so ax equals Fig.
Don't add subplot.
This adds some axes plot don't show where we go so this is just replicated exactly what we did we did
like a kind of a long version of going P ulti felt for same sort of thing here right.
So this is the first method and then you've got the second method
so you want vague equals plot BLT.
And when I say plot I'm referring to.
P L T but because there's no I was just easier for me to say plot.
So creates a figure of being communicated here.
You don't need these comments ax Eagle's fig dot add axes.
And then within here we're gonna add some sample data 1 1 1 1
sorry is going to add axes so these add accesses to the figure.
So there we go.
You've got another figure everyone acts dot plot.
Let's get out x and y on their and then BLT dots show
add some data.
There we go.
We're just creating the same plot.
And now finally we're going to go with the third method and this is the one that we're going to be using.
So we've put in here recommended the reason why I'm showing you all these is because if you look up
Mac plot lib online and you find some documentation or some Stack Overflow answers you might come across
these styles of plotting.
So we're going to use a third method nurses recommended of course.
You can choose your own but this is what we're going to be going through throughout the rest of the
map Gottlieb section.
So this is big comma acts this time.
So we've saved a line of code equals penalty dot subplots.
Now let's see what this says subplots create a figure and a set of subplots.
This utility wrapper makes it convenient to create common layouts of subplots including the enclosing
figure object in a single call.
Now what is this subplot you could think of a subplot as having more than one plot come out at the same
time.
That's all it really is.
And then we're going to go ax dot plot x y
and some data and we'll put a little semicolon at the end instead of calling plot don't show this time.
There we go.
Just re created the same graph three times three different methods but we're gonna be focused on the
third method and you might notice that every time I call something like fig eagles or ax eagles or fig
comma ax Eagles it resets the figure even though we're plotting the same data.
Maybe if we went here and we go 50 100 200 250 it's gonna change it up so every time we call something
like this it's going to reset the figure and plot a new set of data.
So let's wrap it up there.
But in short the main takeaway from this lecture is that we're going to be focused on this method.
There's two different types of methods plotting in that plot lib the pipeline API but that's generally
less flexible it is quicker to get plots up and running sometimes but the object orientated API is going
to allow us to do a bit more fancy stuff in the future so that's what we'll focus on.
I'll see you in the next video.