‫In the numb pie section, we talked about how many Python data science packages are built off numpy
‫arrays.
‫The same goes for map plot lib.
‫And one of the beautiful things about map plot lib is it's about as flexible as numpy arrays.
‫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 than others.
‫Well, some more common ones you're more likely to come across.
‫And these plots are the ones like line scatter, bah haste and subplot or plotting multiple visualizations
‫on one figure.
‫Let's have a look at some of these kinds of plots that you'll see more often.
‫Plots or figures remember that words kind of interchangeable.
‫Using pure numpy arrays.
‫So start it off.
‫So we go making figures with numpy arrays.
‫Like this mock 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 NumPy as MP and we'll start off by create some data x equals np len space zero ten 100 might
‫be going.
‫Hold on, Daniel.
‫We haven't seen Len space.
‫Well in that case remember what can you do?
‫Did you get it?
‫Well, if you didn't, it doesn't matter.
‫We can press shift tab and see what Len Space actually does.
‫Zoom on MP Lin space.
‫Yep.
‫Start stop num.
‫Okay.
‫So there the first three arguments and we've got zero is start.
‫Ten is stop.
‫100 as numb.
‫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 going to 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 going to be 100 samples, so we don't want to see all that, let's say the first ten.
‫Wonderful.
‫Well, let's see.
‫The first 100.
‫Why not?
‫I'm into taking risk, aren't you?
‫So there we go.
‫We've got 100 different samples here, 100 different floats, values here between zero and ten.
‫So we start at zero, goes all the way up to ten.
‫Wonderful.
‫We'll reduce this back to ten to save some space.
‫Excellent.
‫Now let's go plot the data.
‫So remember, we're going to create a fig and an axe or figure and axes.
‫But these are the common short names for figure and axes.
‫We'll go plot subplots, because this is the method that we're going to be using x dot, 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.
‫Let's see what happens.
‫We'll put a little semicolon.
‫Wonderful.
‫We get this beautiful curved line.
‫So the default here in that plot lib when you call plot is a line plot.
‫It's a line plot.
‫So and create a line plot.
‫There we go.
‫So as you can see, just a straight line.
‫Now, use the same data.
‫Let's create a scatterplot.
‫Use the same data because these are the most common types.
‫Let's write these down.
‫We want.
‫Line plot scatterplot.
‫Bar plot.
‫Haste and haste is short for histogram and a subplot.
‫They're the main types of plots we're going to be focused on.
‫Of course there are more, but we could be going all year for the amount of plots you could do in that
‫plot.
‫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 scatterplot and see what a scatterplot is.
‫So if we want to recreate it, we have to always reset fig and ax.
‫If we're in a different cell equals plot, subplots, wonderful acts, now we're going to use scatter.
‫So up 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 scatter on x.
‫So here we go.
‫We want X and then we want n p.
‫Maybe we'll do the exponential of x.
‫And remember, if you're not sure what XP means, you can go shift tab.
‫Read the docstring 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 scatterplot?
‫Let's make another one just so we can see.
‫Fig AX, I want you to get really used to typing out this fig x plot subplots.
‫This is going to be our bread and butter for map plot lib acts 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 wave here.
‫And if you're not sure what this is, what this is a sine wave.
‫And again, you can always see the docstring or look it up and by the steps you can search it up if
‫you're still not sure after looking that.
‫We've been using numpy arrays and that's what this section is making figures in numpy arrays.
‫How about we create a plot directly from a dictionary?
‫So.
‫Make a plot from dictionary because this is just showing how versatile and flexible map flop live is.
‫So if we want my almond butter store will bring that back.
‫So we want not better prices.
‫That's my favorite food.
‫Do you like it?
‫I like it too.
‫So we want here.
‫I'm about ten.
‫It's quite expensive.
‫Peanut butter.
‫Not as expensive where I live.
‫So eight and cashew butter is the most expensive.
‫You are hard to come by, you know, and short supply sometimes.
‫So if we go here and then we've got fig ax equals plot subplots, we're getting really good at this
‫one.
‫And now we want let's do a bar plot this time.
‫So, you know, that's the trend.
‫We're changing this now.
‫I know it's kind of confusing because this is a line plot, but it says plot doesn't say line.
‫You're just going to 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 X bar and we're going to pass it X and y.
‫So X maybe we'll be a bit more formal x equals not butter prices.
‫What do we want?
‫We want the keys from our dictionary because we're using a dictionary now, not numpy array.
‫So we 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 we might put that in a little comment.
‫X Y not but prices dot values.
‫Beautiful.
‫And now we might see what this looks like.
‫Ah.
‫Error.
‫Missing argument height.
‫Huh.
‫That's interesting.
‫I see this.
‫This one doesn't take why that's a problem.
‫Positional argument.
‫Key word 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 x.
‫Well, that is x x equals that.
‫That's what we can't have.
‫We can't have that equaling that.
‫So we're going to leave this at that X bar 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 around.
‫So see how we don't have x equals we can have this bend height equals.
‫It'll come out with 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 we're getting a lot of value from this map lecture here.
‫Now, this doesn't really make sense.
‫We've got a few bars here.
‫You can kind of infer that that's prices.
‫Let's customize it.
‫Let's add a little bit of a title.
‫We want dense nut butter prices store and see that little exploration that we just did before.
‫That's going to happen, right?
‫You're going to make mistakes.
‫You're going to think, you know, things like me and then you're going to go, oh, that's actually
‫not like that.
‫And then you'll look at the docstring, 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 equals 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 dot show note.
‫Well, that has no attribute called show, but we can add a semicolon up here, 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 the semicolon before, but we've just seen where you actually have to put it.
‫It's on the last line where you reference AX.
‫Well, there we go.
‫You can create your own store.
‫We've just seen how to plot from numpy arrays.
‫We'll look it 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 an umpire a and I'll see you shortly.