‫So let's get started with Matt 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 our little workflow like we always do.
‫So we're going to see the for me.
‫I'm going to get into the sample project folder which contains our environment.
‫We can always see our environment by using Conda 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.
‫It's kind of seedy.
‫I'm on the desktop right now.
‫You can see that there.
‫So I'll go into ML course.
‫We can see that little folder up here, but we're going to use the command line and then see it again
‫into sample project.
‫Beautiful.
‫And then we can run con to 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 get used to writing things out for yourself and practicing, seeing what it feels like on your fingers
‫to write code.
‫So if you go to activate, that should be all correct.
‫Wonderful.
‫And so we've had base change from this to this.
‫We've seen all this before.
‫We're going to load up a Jupyter Notebook, our favorite workspace.
‫We've got introduction to numpy and pandas.
‫We've been through those.
‫We're going to start a new one.
‫So now we're going to retitle this one to be introduction to Matt Plot Lib.
‫Beautiful.
‫We'll have a title introduction to map plot 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 Jupyter Notebook.
‫The first step for always using that plot lib is we might import NumPy and pandas as well.
‫So we'll import all the tools we need right at the top of the notebook.
‫This is kind of a regular workflow.
‫So the first one we'll do is map 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 Jupyter, 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 that plot.
‫Lib dot pi plot.
‫Now PI Plot is a python plotting module of map plot lib and the convenient name is as PLT.
‫We'll also get pandas as PD and import numpy as NP.
‫Now 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 that plot lib is with plot dot plot.
‫So if we go shift tab, have a look at what this says, plot X versus Y as lines and or markers.
‫Hmm.
‫What happens if we just run this?
‫Ah och, we get kind of that empty box that we saw before that was in the 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 Jupyter 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 Matt plot lib 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.
‫As the ideal scenario to always run that when you want to run map plot lib plots.
‫And now if we didn't want to use the semicolon, we want it to be a bit more communicative.
‫We could go plot and then plot show.
‫That's going to do the exact same thing.
‫We've got a nice and blank plot here.
‫Now, how about we add some data?
‫So we go plot, plot, and then hit shift tab.
‫Plot X versus 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 an 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.
‫There we go.
‫We've got a line.
‫And 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 one, two, three, four, one, two for y equals.
‫Let's mix it up a little bit.
‫1122 3344.
‫Wonderful.
‫Now let's see what these look like.
‫Plot dot, plot x, y, and we'll put a semicolon at the end.
‫There we go.
‫We notice that our accesses have changed.
‫So now we've got from 1 to 4 on the X and from 11 to 44 on the Y.
‫Okay, let's start and make a bit more sense.
‫This is looking good.
‫Now this way of plotting a map plot lib is referred to as the 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 map plot lib documentation.
‫Because in there it tells us a little bit about different types of plotting in map plot lib.
‫What do we want?
‫Documentation.
‫Tutorials.
‫Pli plot tutorial.
‫So this is the type of plotting that we're using at the moment, not map plot.
‫Lib pie plot is a collection of command style functions that make map plot lib work like matlab.
‫Yeah, that's all we just went through.
‫Each pie pop function makes 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, lib plot, various
‫states are preserved because function calls.
‫Okay, we're just reading the documentation here.
‫So this is the one we're paying attention to.
‫Note the PI plot 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 pie plot API and we're going to look at the object orientated API
‫in a second.
‫But this is the one we're going to 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 life cycle of a plot.
‫There we go.
‫And you can get to this in the documentation as well.
‫So this is just map plot alibaug tutorials.
‫Life cycle of a plot.
‫There we go.
‫This is the same thing in general, trying to use the object orientated interface over the pie plot
‫interface.
‫Okay.
‫So if the documentation is saying these two things in bold notes, we might listen to it.
‫Alright, because the people who write these documentation, they really know what they're doing.
‫So let's say this is the first method.
‫We'll go Fig Eagles.
‫Now Fig is short for fig..
‫PLT Fig..
‫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 dot add.
‫Subplot.
‫This adds some axes.
‫Plot don't show.
‫There we go.
‫So this is just replicated exactly what we did.
‫We did like a kind of a long version of going plt.
‫Help plot.
‫Same sort of thing here, right?
‫So this is the first method.
‫And then we've got the second method.
‫So you want big Eagles plot?
‫Plot.
‫And when I say plot, I'm referring to plot.
‫But because there's no oh, it's just easier for me to say plot.
‫So create a figure.
‫But being communicative here, you don't need these comments.
‫X equals fig dot add axes.
‫And then within here, we're going to add some sample data.
‫One, one, one, one.
‫Sorry is going to add axes.
‫So these add axes to the figure.
‫So there we go.
‫You've got another figure.
‫If we want to plot, let's get our X and Y on there.
‫And then fail to show.
‫And 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 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 StackOverflow answers, you might come across these styles of plotting.
‫So we're going to use a third method, and this is 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 plot lib section.
‫So this is fig comma acts this time.
‫So we've saved a line of code equals plot 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 a subplot?
‫You can 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 Axe Dot, Plot X, Y.
‫Add some data and we'll put a little semicolon at the end of set of calling plot.
‫Don't show this time.
‫There we go.
‫We've just recreated the same graph three times with three different methods, but we're going to 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 fig. even though we're plotting the same data.
‫Maybe if we weren't here and we go 50, 100, 200.
‫250.
‫It's going to 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 map plot lib the pie plot 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.