Hello everyone and welcome to the map plus live exercises solutions lecture in this lecture.
We're going to go over the solutions for the map plotless exercise.
Let's go to an Jump's a notebook to get started.
All right here I am at the notebook for the most part lip exercises.
Let's go ahead and jump right in and get started.
We're going to go out and run that first cell to get the data.
And let's go at an import map plot lived high plot as Piazzi and set map plotted inline.
Now there's one more question which is what Kamandi use if you are isn't it Jupiter notebook.
And as a reminder that would be Piel teeth that show at the end of all your plotting commands.
Let's go to sort of exercise one.
Want to create a figure object called fig using pilt that figure.
All right.
So this is just the object oriented method of using Map plot lib or we say fig is sequel to peel T-Dog
figure.
And then we want to use add underscore axes to add a set of axes to this figure.
And I'm going to go in and say x is equal to Fig dot add underscore axes.
And we actually get the position we wanted that 0 0 1 1.
And then finally I wanted to plot x come a y on that and run this.
OK it looks like we have a good match here and we want the labels and titles to match below.
So if we go ahead and set that in we want to say set X label
to be X and then x x x set y label to be Y.
And we also want to set the title and it should have just been a simple title.
All right.
So what do we do here.
We went ahead and created a figure object added a set of axes a figure object plotted on that figure
object and then set the X label the y label and the title.
Let's go ahead and move on to exercise 2 which is a very similar exercise.
We're going to see a fig circle to peel t that figure to create the figure object.
And then we want to put two axes on it x 1 and x to go and say x 1 and x 2 and I'm going to say fig
thought add underscore axes.
First one is located at 0 0 1 1.
That's the larger one.
And then the second one is located at zero point two point five point two point two.
It's going to run that and it looks like we get a same result here.
Great.
Now continuing to exercise we wanted to do is plot both x and y on both axes here.
Let's go ahead and add that into the cell.
So I will say x 1 plot x y and x to plot x y.
And here we have the same plot right here.
You wanted that to be red.
You could've just added in the color arguments red
you just passed a string and now it will be red to match this lower plot and then if you wanted to you
could have also added in the X labels and the y labels.
It's going to move on to exercise 3 which was create the plot below by adding to access to a figure
object at these specific canvas points.
All right.
So not as much guidance though on exercise 3.
First thing I want to do is create a figure object.
I'm going to say fig is equal to peel T-Dog figure and then the next thing I want to do is begin to
add the sets of axes and when to say x is equal to Fig dot add axes and we'll put them at the same locations
that were requested.
I will say x 2 is equal to Fig dot and underscore axes or we'll set these up point to point five point
four point four.
All right Rennie that looks like we get the same result and then coming up next we wanted to use the
x y and z arrays to recreate this plot below.
Let's go ahead and check out that plot below to comment these out and bring this a little closer so
we can see it.
Zoom out a little bit.
OK.
So it looks like we have a couple of things going on here in the outer Plaut we have X versus Z.
Let's go in and add that in.
So in the large plot which is X in our case it's going to plot x versus Z and I'm actually going to
set the labels for that.
So the X label wups set X label set that to X and that X are set y label set to Z.
So this is the large plot and now it's going to talk about the insert plot.
So if we take a look at the insert plot has going on it's going to be X by Y.
Over here it looks like the title is zoom.
So I'm going to go ahead and say X plot x y and then I'm going to set the title to be zoom in I'm also
going to go ahead and set those labels to be X and then or the Y to be y.
You know we're actually not quite finished yet let's go and run this and see what difference we get
.
So note right now I made a mistake that should have been on the insert.
So this should have been x 2 for all of these.
Now let's go ahead and run this.
And this is looking OK but there's still a difference here.
Notice on the zoom the x and y limits X goes from 20 to 22 and y goes from 30 to 50.
Here we're just using the default limits.
Let's go in and change those on the insert.
That's going to be x 2 dot
set X slim and we want to go from 20 to 22.
Let's go and add that in 20 to 22.
And I'm also going to set the while him and if we scroll back down we can see the whilom went from 30
to 50.
So we'll say 30 comma 50 in the slowest.
Run that.
And now we can see that we're matching completely on both the insert and the outer plot.
All right now we're on exercise four.
Let's go ahead and use PELTOLA subplots to recreate this plot below.
I'm going to say fig come axes is equal to peel t thought subplots and I want one rule by two columns
.
Let's go in and run that and looks like we get that output correctly.
Now we want to plot x and y and x versus Z on the axes and I want you to play around the line with and
style.
Let's see if we can match these up correctly.
I'm going to go ahead and plot over here.
Let me empty that out and let's go ahead and say axes 0 members using subplots.
Now so we're going to be able to iterate or call this sequence of the array of axes.
So I'm saying axes zero plots and it looks like I'm going to go ahead and mess around with this will
say X Y and on axes one will go in and plot x z.
You know it's going to set these colors so we'll see color for the second one to be red and it looks
like the line with a little ticker.
And then this one the first one looks like let's go in and set the colors to be blue as a string.
And it also looks like the line style s is a dashed line.
Go and add that in.
It also looks like it's a little thicker sole but in LW equal three it's going to run this if we get
everything looking OK.
All right.
Not bad.
Looks like we're getting a match.
And now we wanted to see if we could resize the plot by adding in this fix size arguments.
Let's go in and check that out.
Remember we can just add size arguments into the subplots call so we can say fig size is equal to and
looks like we want wide and short.
So on the first number to be larger so some wider numbers which just fell in the second number to be
smaller so we're going say 12 to.
And if we run that looks like we get a match to the second plot over here.
And there are also messed around the styles a little bit.
So switch it up all of us would go in and do that ourselves.
We just say something like.
LS over here is equal to dash lines.
Now we switched it and matched it.
All right.
That's it for the exercises for Matt plot lib hopefully really drilled in as far as the syntax for using
Object Oriented map plot live.
All you have to do is say call the figure axes of the figure and then plot on those axes or if you're
using subplots as in the last problem call fig come axes to peel to those subplots and then iterate
through those axes or call using the array of axes to plot each particular subplot.
That's really all there is to it.
Go ahead and review the solutions book in case any of this was unclear or feel free to post the question
to the Q&A forums.
Thanks everyone and I'll see you at the next lecture