Hello everyone and welcome to the mat Partlet part to lecture series.
We're going to pick up right where we left off in part one where we learn about functional programming
with that plot.
And more importantly the object oriented methods with Matt plotless.
Let's go ahead and jump back to the Jupiter notebook to get started.
OK.
Here I am back at the Jupiter notebook number from last time we learned how to use that figure and then
figure out axis and then axes that plot in order to plot onto an object oriented figure using that plotless
.
The next thing we're going to do is learn how to create subplots using the same object oriented programming
method.
I'm going to go ahead and say Here let's just clear everything in this cell and we're going to go ahead
and say this and move the cell to the center and we'll say fig comma axes is equal to peel T and instead
of calling figure now says we're going to try to do subplots we're going to say subplots so appeal to
the subplots.
Let's go ahead and run this.
And notice here we get subplots just out.
Now what I can do is just use the axes object like I've done before to plot on it.
And this is essentially no different than what we were doing before.
And here he said X is that plot x come a Y where subplots differs is where you can specify the number
of rows and columns.
For instance I can say and rows as my first argument is equal to 1 and calls as my second argument is
equal to two.
And I'm going to go ahead and just show you what that looks like a hash tag that out and run this.
Now you can see I have one row with two columns and that's basically just a nice front handle on calling
Piel T-Dog figure also plot's is doing is essentially calling these fig axes automatically for you based
off of these arguments and rows and columns.
Let's go ahead and play around with this let's go show one more example.
Three rows by let's go in and say three columns and we see now we have three rows by three columns.
Later on we'll see how to deal with the issue of stuff overlapping but it's essentially just a one line
call.
We just say peel t Titely out and that actually ends up fixing those overlaps.
Let's go out and take a step back and just work with this one by two.
All right.
We have realty that subplots.
And essentially it's just an axes manager on top of Piel to that figure.
Something to note here is that instead of just saying fig equals PBT the figure I am doing some tuple
and packing them saying fig comma axes is equal to peel teeth that subplots and the thing to know about
this axes object is if I go down here to this cell and type in axes axes is actually just an array of
map plot lib axes essentially it's just a list of these axes object meaning I can actually iterate through
it.
I can say something like this for current underscore letters X in axes axes dot plot x come a y.
I don't actually want to say X is not plot.
I want to say current X stop plot and then we see that we've actually plotted through this axes.
Again this is just to show that this axes object is essentially just a list of map lib axes which are
the ones that you manually created when you said Fig.
Add underscore axes just further driving the point home that the only difference between Pilani that
subplots and just doing pilt that figure is that Piel t that subplots is essentially doing this at underscore
axes stuff for you automatically based off of how many rows and columns you want.
OK.
Since we can iterate through this axes object we can actually also index it.
Meaning I can say axes 0 Dopp plots X come a Y and here I've plotted on this first axes.
Now I can do the same thing.
The second one I can say axes 1 dot plots y comma x.
And here we seen how to either index call offer the axes array or iterate through this axes array and
just like we saw earlier we can also call titles and labels off of this so I can say something like
xes 0 set title will say first plot and then I will say axes 1 underscore title second plot and hero
are able to call titles and you can say the x labels set y label off of either of these axes objects
.
All you're doing is just actually grabbing that axes subplot object based off of its position in the
array.
All right.
Let's do a quick review of these two object oriented methods.
This first method is a little more manual.
It's Piel T-Dog figure.
You go ahead and create that figure you manually add the axes and choose its location and size and then
based off the axes you go ahead and say that plot and that title X label set y label etc. which we show
examples up here.
The second method is for subplots that you want arranged by Rosing columns.
This allows you to call fig comma axes so tuple in packing here is equal to the subplots call and then
based off of those axes you get an array of axes and you can plot and set titles either by indexing
or by iterating through that axes object.
And if you ever have any issues with things overlapping You can always just say peel T-top tightly close
parentheses and this will take care of any overlapping plots.
I recommend that you just always put this at the end of your plot statements.
OK now start talking about figure size aspect ratio and GPI map Cutlip allows you to control each of
these aspects and you can specify them when you're calling the figure object.
Let me go ahead and show you an example.
I'm going to say think equals Piel figure and the arguments I can passen are Figgs size is equal to
.
And then you pass a tuple where the tuple is the width and height of the figure in inches.
For instance I can go ahead and say three by two and then a second argument you can add is GPI for instance
100 GPI where the API just the dots per inch or pixels per inch.
I usually just use the default GPI when I'm working with the Jupiter note book.
So I'm going to go ahead and just clear that for now I'm going to add a set of axes to this call it
just X and we'll say fig dot add underscore axes and we'll say 0 0 1 comma 1 and then I'm going to go
ahead and say X stop plot x come a Y.
All right.
So there's our plot.
Let's go ahead and mess around as the figure size.
Let's say we wanted this to be very wide.
Go ahead and say 8 by 2.
And now I have this to be 8 inches by 2 inches.
All right.
So you can do the same thing with subplots I could say peel t that subplots set that Fig's size member
here.
Now we're going to say fig axes and I'm going to go ahead and remove the axes.
Set the figure size and the axes will go ahead and plot onto the first axes.
I'm going to just say axes dot plot x y and I get a very similar plot.
Now I'm going to go and specify some rows and columns for this subplot will say and Rose is equal to
1.
It's actually make two rows and we're going wide here.
And then let's say we have one column.
So and calls is equal to 1.
Now I'm going to call 0 here.
Plot X come a Y and then we'll say axes one dot plot y comma X. And here it can see the FIG size has
taken this into account as far as two rows by one column.
And as always since we have a little bit of a real up here site try saying peel teeth tightly out and
this will attempt its best to fix up the type layout and it looks like it did a pretty good job here
.
There's some issues here with this y axes but I'll show you later how you can customize this y axes
to show a little less information.
All right.
Now that we've finished discussing figure size and GPI Let's go ahead and make a new cell and begin
discussing how to actually save a figure in order to save a figure.
You can use map plot lived to generate just high quality outputs in a number of formats including pian
GJ peg.
SPG TGF and PTF to save a figure to a file you can use the save thig method.
So for instance we have our figure here that we already created.
Remember that's just right here Fig.
And then I can save fig dot save fig and all you have to do is pass in the file name you want.
So for instance my underscore picture and then you pass in the extension and map Cutlip is smart enough
to know what you want.
So if you want to PNB you say up here in G if you want to JPA you say that J peg JP G etc. and say this
as that P and G.
And that will automatically say the figure.
Here you can also specify the CPI.
So if you forgot to specify the CPI over here when you're actually creating the plot you can specify
again DPR over here.
So you can do this if like a 200 GPI and you can increase the DPA as you want more detail.
All right.
We've already got over figure titles and axes labels such as set the X label and set the y label but I'll
show you a quick reminder of how to do that.
We're going to change this back to just a simple fig equals Piel T-Dog figure.
Go ahead and add a set of axes to this.
So we'll save Fig.
Add underscore xes we'll put them at 0 0 1 1 and then we'll say X stop plots X come a Y.
All right.
So as a reminder if you want to add a title you take one of these axes and you say set title and you
just pass in a string of the title you want in order to set a y label.
You just say set y label in a string of the y label you want.
And then for Ex-Slave all you can do the same thing set the label you want.
OK so I have my title my wife label and my X label.
Let's talk about legends with legends.
You can use label text to actually clarify what plot is what plot and I'll show you what I mean by that
.
I'm going to go ahead and remove this these three lines of code and say x start plot y comma X..
So notice I'm just doing this on the same figure.
Meaning if I say and actually run this I will get two lines here I will get the x y plot and the y exploit
.
Since these are quite different Let's go ahead and get something that's a little more similar.
I'm going to go out and plot x versus x square and X versus x Q..
All right.
So now we have two lines here.
And if you were just looking at this figure by itself without being able to reference the code you're
probably a little confused as to what each plot represents.
You wouldn't want to add in a legend in an order.
Add in the legend.
It's actually quite simple but it's a two step process.
The first step is to just call X that Legin at the bottom of your code where your axes are the find
and if you run that you will notice you get a warning it says no labeled objects found.
And that's where the second step comes in.
For each of these plot calls that you just made you're going to add in an argument called label and
this label is just a string that you want.
For the X that legend function to be able to reference let's go to show you what I mean by that we can
go ahead and say X squared here as our label and then and this label.
I'm going to go ahead and say
execute.
And now when I run this if X legend I see I've been able to create a legend.
So all this does when you call X that legend is it looks for each of the plot calls and then checks
to see if there's a label.
And then the label which is just a string gets returned and gets matched up to the correct color of
your line.
And later on we'll show you how to actually customize your line colors.
Now quick no is that.
Notice how some of this legend overlaps the actual plots which you can do in the X that legend call
in order to avoid this is specify ellos.
Now they're actually quite a few locations you can specify and I'll show you the documentation page
real quick for it.
It's linked in your notebook in this section.
Let me go ahead and go to that link so that link will take you to a page that looks like this.
And you can click legend and there's basically a set of parameters here and there's a location code
and a location string.
So you can specify the best upper right upper left lower left etc. based after location code.
I would always recommend that you just use location code 0 because that allows map lib to try to choose
the best location for your legend.
Let's go ahead and do that.
We'll go in and say Alosi call 0 plot that out and if we see that the best location is over here in
the top left let's go ahead and check out one more location code.
If we go back here for instance if we wanted it in the center we can specify a location code 10.
And here we have in the center.
Now if none of these options are working for you such as 0 through 10 which you can do is you can also
specify a tuple giving the x and y of the lower left corner of the legend.
So for instance we can go ahead and say something like this 0.1 comma 0.1 and that means just like you
did earlier when you're putting in an insert plot.
You can put in a tuple here specifying the location of where you want your legend.
Bottom corner to be.
All right.
That's it for this second part.
Coming up next.
On this last part of the map Partlow concepts lecture.
We're going to talk about setting colors line with and line types as well as working with markers setting
the plot range and then we'll begin to talk about some special plot types but that will lead us more
into our discussion of seaborne.
All right thanks everyone.
Go ahead and post any questions you have to the Q&A forums and I'll be happy to answer them there.
Remember to reference the notebooks for this lecture.
OK I'll see if next lecture