In the NUM pi section we talked about how many Python data science packages are built off.
PI a raise.
The same goes for Matlock lib and one of the beautiful things about map plot lib is it's about as flexible
as an umpire raise if you can dream up a way to visualize data.
Chances are you can do it in map plot lib but there are some common kinds of visualizations and others
or some more common ones you're more likely to come across and these plots are the ones like line scatter
bar haste and subplots or plotting multiple visualizations on one finger.
Let's have a look at some of these kinds of plots that you'll see more often plots of figures.
Remember that words kind of interchangeable.
Using pure num pi arrays so started off.
So we making figures with NUM pi arrays will make this mark down so it's a little bit communicative
and then we'll go import.
If you haven't already done this we've done this at the top.
I will do it again.
Import num pi as MP.
I will start off by create some data.
X equals NDP dot Lin space 0 10 one hundred maybe go on hold on Daniel.
We haven't seen Lin space.
Well in that case remember what can you do.
Did you get it.
Well if you did it doesn't matter.
We can press shift tab and see what Lin space actually does.
To an MP Lin space.
The start stop numb the case then the first three arguments we've got zero start tennis stop 100 as
now.
All right well let's have a look.
Return evenly spaced numbers over a specified interval.
Returns num evenly spaced samples calculated over the interval start stop.
So it's gonna return num evenly spaced intervals between start and stops.
What do you think will happen here.
Well if in doubt run the code let's check it out.
Well there's gonna be 100 samples so we don't see all that.
Let's see the first 10 wonderful.
Well let's say the first one hundred one on I'm going to taking risk aren't you.
So there we go.
We've got 100 different samples here 100 different floats values here between 0 and 10.
So we start at zero.
Goes all the way up to 10 wonderful or reduces back to 10 to save some space.
Excellent.
Now let's go plot the data.
So remember we're going to create a fig and an ax or figure and axes but these are the common short
names figure in accessing go plot subplots because this is the method that we're gonna be using axe
stop plot x and let's do because plot takes x and y but we don't have a Y.
Let's just do X to the power of two.
Well let's see what happens.
We'll put a little semicolon wonderful we get this beautiful curve line.
So the default here in that plot layer when you call plot is a line plot.
This a line plot.
So and create a line plot area.
So as you can see just a straight line.
Now use the same data.
Let's create a scatter plot.
Use the same data because it's the most common types.
Let's write these down.
We want
fly plot scatter plot bar plot history and history show for histogram and a subplot.
They're the main types of plots we're gonna be focused on.
Of course there are more but we could we go on all year for the amount of plot you could do a map plot
lib.
So we'll focus on the baseline ones and then you can build upon that knowledge so we want you same data
to make a scatter plot.
See what a scatter plot is.
So if we want to recreate it we have to always reset fig and ax.
If we're in a different cell equals P LTM subplots.
Wonderful acts.
Now we're gonna scatter so here we use dot plot but if we want to scatter plot we'll see what that looks
like in a second.
We need to call dot scatter on ax.
So here we go.
I want X and then we want end p.
We'll do the exponential all x.
And remember if you're not sure what he XP means you can go shift tab.
Read the docs string here what it says it is and if it's still not clear you can look up the documentation.
There we go.
Well it's kind of like a line but a scatter plot is just another word for lots of dots on the plot.
These are really close together these dots so they kind of look like a line but they are all just dots.
All right.
Well how about another set upon let's make another one.
Just so we can see fig acts.
I want you to get really used to typing out this thing X P L T dot subplots this is gonna be our bread
and butter from that plot lib acts dot scatter x let's create a wave because we did one of those before
and that was my joke.
Beautiful.
So we got a nice little wife here and if you're not sure what this is.
Well this is a sine wave.
And again you can always see the dock string or look it up.
No this stamps you can search it off if you're still not sure after looking that use a num ply arrays
and that's what this section is making figures an umpire raise how about we create a plot directly from
a dictionary.
So make a plot from a dictionary because this is just showing how versatile a flexible map plop live
is.
So if we want my arm and by the stall we'll bring that back.
So we want not by the prices.
That's my favorite food.
Do you like it.
I like it too.
So we want here one by 10.
It's quite expensive.
Peanut butter.
Not as expensive.
Where I live.
So aid and cash about is the most expensive cashews are hard to come by you know in short supply sometimes.
So if I go here and then we've got fig X equals BLT or subplots we're getting really good at this one
and now we want let's do a bar plot this time.
So yeah I the trend we're changing this now I know it's kind of confusing because there's a line plot
but it says plot doesn't say line you're just gonna have to get used to the fact that the default map
plot lib is a line plot but now we're going to create a bar plot so acts dot bar and we're going to
pass it x and y so X maybe we'll be a bit more formal X equals nut butter prices what do we want we
want the keys from our dictionary because we're using a dictionary now not known by array so you want
the keys here and our y value so we'll type in y that's what plot or bar or scatter always take X and
Y might put that a little comment x y not but our prices dot values beautiful and now we might see what
this looks like huh era.
Missing argument.
Right.
Huh that's interesting.
I see this.
This one doesn't take why that's a problem positional argument.
Keyword found.
What if we get rid of this.
My bad.
This doesn't take X and Y see you're learning something new every day shift type x is x x equals that
and so we can't have we can't have that equaling that.
So we're going to leave this at that act stop our shift tab.
So this is a little Python thing if you haven't seen this before it's a syntax error where in a python
method if you have a positional argument say x equals this you need something after it to go like say
Y equals this you can't have X equals something and then followed by that but you can have it the other
way round so see how we don't have x equals.
We can't have this bean height equals it'll come out the same thing.
So the first one can't have positional argument where the second one doesn't.
But the second one can and the first one doesn't have to.
That's a little bit of a python tidbit there.
So getting a lot of value from this map plot.
He likes it here.
Now this doesn't really make sense.
We've got a few bars here.
You can kind of infer that that's prices.
That's customize it.
Let's add a little bit of a title may want and not about our prices store and see that little exploration
that we just did before.
That's gonna happen right.
You're gonna make mistakes you're gonna think you know things like me and then you're gonna go oh that's
actually not like that and then you look at the dock string you'll fix it up and you'll combine your
previous knowledge and go oh that's why that's like that.
So don't worry if it happens to you it happens to me.
Why label your price.
But what we do is we strive forward and we figure things out shift into.
There we go.
That looks a bit better.
And what can we do to remove that ugly line of text there.
I believe we can do X not show.
Nope.
Well that has no attribute called show but we can add a semicolon up.
Yeah I believe or maybe down here yeah okay there we go.
So we're learning on the fly here.
If you want to remove that nasty line of output code you can add a semicolon to the last line where
you call ax.
We've seen this semicolon before but we've just seen where you actually have to put it.
It's on the last line where you reference ax.
There we go.
You can create your own store.
We've just seen had a plot from num PI a raise.
We'll look at a little bit more in the next video but to prevent this one from getting too long.
We'll pause it here.
So take a little break.
Create your own plot from a dictionary or a nun pie array and I'll see you shortly.