Hello everyone and welcome to the first map plot lib lecture and this lecture we're going to begin to
show you how you can use map plot lived with Python.
Let's go ahead and jump to the Jupiter note book to get started.
All right.
Here I am at the notebook the notebook for this lecture is called Math lib concepts lecture and all
the code are going to be doing is located in this notebook as well as a lot more information that's
available to you regarding that plot lib.
OK.
I'm going to go ahead and jump to a blank notebook and walk through all this code and explain it for
you.
Let me go out and click this new tab and here we have this new notebook.
When you go ahead and hide the header and toolbar just get a little more room here.
OK.
Let's go to get started about plotless.
Once you've installed met.
The first thing you're going to be able to do is say import map plot lib pie plots as TLT and then if
you're using the Jupiter note book what you're going to do is say percent sign Matt plot lib space in
line and that's going to allow you to actually see the plots you create inside the Jupiter notebook
.
Go ahead and run this great.
If you are not using that Jupiter notebook's system what you going to go ahead and do is at the end
of all your commands for plotting which will show later what you will type is Hilti that show close
parentheses and later on and we actually start plotting some examples.
Asha you would actually put that into your code.
All right.
Let's go ahead and walk through the very simple example using two numpy race going to go in and say
import them PI and P and say x is equal to any Lynn space.
So it's going to be linearly spaced we'll go from 0 to 5 and grab 11 points and then y is going to be
equal to x.
So the power of two.
So if we take a look at x and y we have an array from 0 to 5 and then WHY are just all those elements
squared.
Now basic map plot Lim commands allow you to very quickly create a plot and we'll show you two ways
of creating map plotted plots.
One is a functional method and the other one is the object oriented method will show the functional
method first and then we'll shift over to the object oriented method.
Since that's usually the better way of creating a about Cutlip plot let's go and show you the functional
method first the functional method is actually quite simple.
You say peel t got plots and then we can do shift tab here and you're going to pass in several arguments
.
First one you're going to do for just a basic plot is passing your X and your y elements and then we
can go ahead and do shift enter.
And here this will actually show the plot.
We've went ahead and plotted X versus Y.
If you're not in the Jupiter note book which you are going to do at the end of this line if you're in
your code say peel t show and then if I run that we can see we get the same plot.
You don't have to use t show unless you're using something that's not that Jupiter note no but the difference
in the Jupiter notebook is essentially like you're printing the plot.
Notice here if I don't have PBT that show I get out.
So if I remove this or actually put it back in then I don't get the out.
So that's essentially the same thing just to do a quick analogy as typing a string versus saying print
the string
and that's the exact same thing.
What KEELTY That shows doing is essentially printing out this plot instead of just showing the plot
.
All right.
For now on we won't actually concern ourselves with concert's consistently typing appeal to that show
.
However if you're not using Jupiter note book you will have to keep typing that.
So just keep that in mind.
All right.
So that's the most basic way to plot something about polyp which isn't so bad.
You can actually add that plot Matlab like arguments such as color and lifestyle.
And that will allow you to continue to edit this plot.
We'll talk a lot more about this later on as far as line styles and color styles but if you're familiar
with Matlab this probably already seems familiar to you.
Let's go to remove that for now and just go for the basics.
If we want to add an X label y label or title to this plot we can do that with the following methods
.
Can Say T X label and then just passing a string you want for the X label or go out and say X label
and then for the y label you can say p t y label pass in a string why label them for the title you can
say Piazzi that title and then we'll just go ahead and put in the title string there.
Go ahead and run this.
And now we can see we have an X label a y label and a title.
And later on we're going to learn how we can specify the CPI or dots per inch in order to get some more
clarity here such as a finer font.
Let's go ahead and continue on with creating multi plots on the same canvas.
We're going to go ahead and scroll down here.
Remove the cell and talk about putting multi plots on the same canvas nerds to do that.
We're going to say peel t subplot and subplot takes in couple of arguments as well.
Right now we can't see them so I'll go and tell you the first one is going to be the number of rows
.
The number of columns and then the plot number you're referring to in this case we'll just go ahead
and say one and we'll go ahead and plot something on that cell.
Will say X Y and we'll go ahead and specify that it's the color red string are as a third arguments
begin.
Don't worry too much about fully understanding this because once we get to the object oriented method
a lot of this going to make way more sense.
But I just want to show you what's possible for now.
Well let's go ahead and say another appeal to that subplot we specify one row by two columns.
And the third argument is the plot number.
Now we're going to edit the second plot and we'll say peel t that plot.
Well go ahead and do Y versus x and specify B for blue as a string.
Here let's go ahead and run this and see what we get.
OK so now we have two subplots here that's creating multiple plots on the same canvas.
Now we're going to do is after we've seen the very basics of creating a plot we're going to break this
all down for a more formal introduction to that libs object oriented API method.
And this means we're going to instantiate figure objects and then call methods or attributes from that
object.
And that's going to be a much better way of actually using that plot live.
So the basics for now are just using PBT the plot and then putting in your data or GLT that subplot
specifying the number of rows and columns and then the figure we are working on and then using Kilty
that plot.
Let's go and switch gears to the object oriented method and this is going to be much better.
The main idea in using the more formal object oriented method is to create figure objects and then just
call methods off of this.
Let me go in and show you what I mean by that.
I'm going to go ahead and say fig is equal to peel t figure and I'm going to go in and close the princes
there.
Now if I just run that cell.
Notice I have a figure object has been created this figure object you can think of it as just kind of
this imaginary blank canvas.
And we can add a set of access to this campus.
So in the same cell I'm going to say XS is equal to Fig dot add underscore axes and I'm going to add
a set of axes.
And the way you can add a set of axes is by passing in a list and the list takes int for arguments a
left bottom width and height arguments that range from 0 to 1.
Basically the percent of that blank canvas you want to go ahead and take.
Let me go in and show an example.
And again I'm kind of going to be showing you a lot of stuff that won't make sense at first but everything
will make sense at the end as you see repeated examples and you break it down further.
So I'm just typing in some numbers here.
This is going to be left of the axes.
It's going to be the bottom of the axes.
And this is going to be the width and the height of the axes 0.8.
Let me go ahead and run this on the cell.
And now notice what I get here.
Now I have a blank set of axes.
So I said P-T that figure created a figure object and then off that figure object I called the method
add a set of axes and passed in a list of where I actually want the axes to be placed next what I'm
going to do is actually plot on that set of axes.
And this is going to feel familiar to what we just did earlier.
You're going to say axes stop plots and let's go ahead and plot x and y on that set of axes and then
do shift enter.
And now you can see we've basically come up with the same plot we did earlier except using an object
oriented method.
So if I scroll back up here this is the plot we did earlier we just said Appeal teed that plot but now
using this sort of object oriented method we're going to have a lot more control over this.
It's a little more involved as far as the steps we need to take.
But it's definitely worth it.
So we've created the figure we called the figure method.
Add axes on this pass then a list of axes and then plotted on that sort of axes if we want to continue
by putting x labels y labels and titles.
You can go ahead and do that on that set of axes.
You can say set underscore ex-slave.
It's a little different from the peel T which is just X label.
When you're working at this Xs object you're going to say sets underscore.
And now we can go ahead and pass in the string x label and you're going to do the same thing for y labels
lips y label.
And let's go ahead and do the same thing for a title set underscore title
now if we run this we should see our new labels X label y label and set title.
Let's go ahead and continue this idea of object oriented programming with that live by putting in two
sets of figures on one canvas.
And this will start to make sense as far as what this list is referencing.
I'm going to go ahead and scroll down to a new cell and zoom in a little bit just so we can get a very
clear picture of what we're actually doing here.
I'm going to say fig is equal to realty figure.
So I'm creating that figure object.
So there's my figure object.
I'm going to say axes one is equal to Fig dot axes.
I don't mean to go hand in set main axes it will be zero point one zero point one and then zero point
eight 0.8.
And again this is the left the bottom and then the width and height of that sort of axes.
And then I'm going to add another set of axes column axes two going to say fig and underscore axes.
And then when I'm going to go ahead and do is basically put inserts axes I'm going to say the bottom
of the set of axes starts 20 percent from the left 50 percent from the bottom.
So excuse me here I'm talking about basically this.
This bottom corner of the axes sluffed and the bottom.
So 20 percent in from the left 50 percent up from the bottom.
And then we will say it takes up 40 percent of the canvas size and width and 30 percent of the canvas
size and height.
So all these values here must be between 0 and 1.
Let's go ahead and run this and know what we get out.
We get out this basically insert set of axes and hopefully now you can begin to see what these values
actually correspond to what I want you to do now is go ahead and pause the video and play around with
these numbers.
Make sure they're all either between 0 and 1 and see how they correlate with this set of axes.
Go ahead and just play around with axes 2 and move it around.
For instance try to get this sort of axes to over here at this bottom corner.
Good impulsivity.
See if you can move this insur over to the bottom corner.
All right.
I'm going to see if I can do that now.
So if I want this at the bottom corner I probably want to say that it goes left bottom width and height
.
So I will try shifting it down by making this basically just 0 so start.
Well it's going to say 0.1 here start at zero 1 5.
So a little off the bottom of this insert here of Axis 1 will go ahead and run this.
And there I was able to move it more towards the bottom remember this second one is the bottom.
And now we want to move more towards the right which means from the left a one or two percent.
Wise move this bottom corner more over from the left.
Let's go to set this as 8.
And that looks like shifted it a little too much.
So let's go in and shift it back to maybe five and there we can see we have it now in the bottom.
All right go ahead and play around if that.
If these figures are these numbers are still a little unclear.
Remember they're basically just denoting the left bottom and the width and height from range 0 to 1
relation to the blank canvas.
We're going to go ahead and reset these to what we have in that originally 0.2 and 0.5.
So we have our little insert there.
And then what I'm going to do is go ahead and plot on these axes.
So I'm going to say axes one plots and I will say X come a Y and then I will say axes two plots will
go and say why come x Let's go and run this.
And here I can see now I have my little insur and my outer plot and then I can keep adding stuff on
each set of axes if I want my insert to have a title for instance that's axes to.
I can say axes to the set title and we'll go and say insert.
Well it's going to make it very clear we'll say smaller lots and then on axes 1.
Let's go ahead and set a title
and we will set this title as larger clots going and run that.
So notice what happened here.
I actually got an error because I didn't actually see smaller plot because I forgot to put a 2.
Here let's run this one more time.
OK now we are getting what we're supposed to get.
We have larger plot and smaller plot.
And basically that's the idea behind object oriented programming that Portland you create a figure.
And that's essentially just an empty canvas.
So let me go in and show that one more time just by putting this in a cell by itself.
We create this empty figure there's nothing to show.
And then you add a set of axes to it by saying axes whatever one or two etc. equals fig thought at underscore
axes and you pass and this list that goes from left bottom and then the width and the height in relation
to this empty canvas.
So if we run this then we have our empty set of axes and then you can plot off those axes you can say
axes one plot and then X come a Y.
All right.
This is the sort of methodology we're going to be working with for a map Cutlip as far as the very basic
way of working that plotless which is the functional method.
You can just say appeal to that plot or peel that subplot.
We're going to learn how to create subplots using this object oriented method which is going to be a
lot more efficient and grant us a lot more control.
OK.
Go ahead and review this section of the map plot lib concepts lecture no book.
There's a lot more notes and a lot more comments in the note book in case any of this confused you but
hopefully by now you have a full understanding of basically this.
These lines of code right here if you understand what's going on in the cell then you're pretty much
good to go.
We just create a figure.
We add an axes to that figure to find the location of that set of axes with this list and then you can
plot on that sort of axes you can set the titles at the X label y label etc..
All right.
Thanks everyone.
And I will see you at the next lecture or we're going to continue this discussion off of the same Jupiter
notebook.
Thanks and I'll see you next lecture