Coding

Intro to Data Visualization in Python with Matplotlib! (line graph, bar chart, title, labels, size)

  • 00:00:00 what's up guys and welcome back to
  • 00:00:01 another video sorry that I have been
  • 00:00:03 gone for a while now I was really busy
  • 00:00:06 finishing up my master's degree but that
  • 00:00:08 is all done with now so I'm happy to be
  • 00:00:10 back and happy to be able to me making
  • 00:00:12 some more videos so in today's video we
  • 00:00:15 will go through the bat plot live
  • 00:00:16 library of Python and this is a super
  • 00:00:19 useful library for all things data
  • 00:00:21 visualization in Python so the video
  • 00:00:24 will start off with going through the
  • 00:00:25 matplotlib basics so as you see on the
  • 00:00:28 screen will be creating like lying
  • 00:00:30 graphs such as the one you see here
  • 00:00:31 you'll learn how to format these lines
  • 00:00:34 in different ways you'll be able to add
  • 00:00:36 a title you'll be able to add labels to
  • 00:00:38 your x and y-axes format your tick marks
  • 00:00:42 properly add a legend etc so all the
  • 00:00:44 kind of basic matplotlib things you want
  • 00:00:46 to know then we'll move into other types
  • 00:00:49 of graphs such as bar charts and we'll
  • 00:00:52 finish this video off with going through
  • 00:00:54 all sorts of like real world examples
  • 00:00:56 where you can kind of combine your data
  • 00:00:58 science skills that you might have using
  • 00:01:01 like pandas library and if you haven't
  • 00:01:03 learned anything about the pandas
  • 00:01:04 library I recommend you watch my video
  • 00:01:05 on that so with that the kind of real
  • 00:01:09 world examples will do stuff such as
  • 00:01:10 like plot the USA versus Canada gas
  • 00:01:13 prices off of data that we have little
  • 00:01:16 link to in a CSV we'll do some histogram
  • 00:01:19 stuff we'll do some pie chart stuff and
  • 00:01:22 we will do some box and whiskers chart
  • 00:01:25 stuff I can't get through every type of
  • 00:01:27 graph in this one video but if there's
  • 00:01:30 certain things that I didn't cover and
  • 00:01:31 you really want me to cover let me know
  • 00:01:33 in the comments that would be super
  • 00:01:35 duper yeah
  • 00:01:38 that's all I got to start this video
  • 00:01:40 let's just jump into it all right let's
  • 00:01:42 start out by loading in the libraries
  • 00:01:44 that we need for this tutorial so we're
  • 00:01:45 an import map plot live as our dot pie
  • 00:01:49 plot as PLT we're going to import numpy
  • 00:01:55 as NP and we're going to for the later
  • 00:01:57 examples import pandas as PD and run
  • 00:02:01 that so if you have all these us like
  • 00:02:04 already installed he won't get any
  • 00:02:05 higher so if you do get these get an
  • 00:02:07 error when you're
  • 00:02:08 to run among these you find need to
  • 00:02:09 install it so you can either do a pip
  • 00:02:11 install a map plot lib pip install numpy
  • 00:02:14 pip install pandas or you could install
  • 00:02:16 a Python distribution that already has
  • 00:02:18 these packages such as anaconda I'll
  • 00:02:20 link to how to do this in the
  • 00:02:21 description okay so now we have our
  • 00:02:23 libraries loaded let's now build our
  • 00:02:26 basic graph so I always think it's kind
  • 00:02:37 of the hardest part about anything with
  • 00:02:39 Python in general is starting with that
  • 00:02:41 blank blank space so what I recommend
  • 00:02:44 for matplotlib is always start at the
  • 00:02:47 documentation so I have a link for this
  • 00:02:50 in the description but here is the home
  • 00:02:53 page of the matplotlib PI plot
  • 00:02:55 documentation and what I recommend is
  • 00:02:57 like whenever we're trying to do
  • 00:02:58 something new just do a ctrl F and like
  • 00:03:01 look for it so if we look for plot here
  • 00:03:03 that's like we're just trying to get a
  • 00:03:05 line graph on the on the screen box
  • 00:03:08 plots not when we don't want it then
  • 00:03:10 plot ok this looks good plot y versus X
  • 00:03:13 as lines or markers so this is what
  • 00:03:15 we'll start off by doing as you can see
  • 00:03:18 right here and the examples it gives
  • 00:03:19 gives plot X comma Y so that's the
  • 00:03:22 command we'll have to run to make this
  • 00:03:24 work and just to know what x and y are
  • 00:03:27 if we go down to parameters they tell us
  • 00:03:30 that commonly these parameters are 1d
  • 00:03:33 arrays so we know we need to pass in 1d
  • 00:03:35 array to the plot function so if we do
  • 00:03:38 plot 1 2 3 that's going to be our x + 2
  • 00:03:46 4 6 will be our y I can't type and run
  • 00:03:51 that plot is not defined so we imported
  • 00:03:56 pipe lot as plot so when we run this
  • 00:03:58 function we actually have to do P love T
  • 00:04:00 dot plot and then this is our X and the
  • 00:04:05 second array is
  • 00:04:06 I so let's see what happens there yay we
  • 00:04:09 get a graph and to clean this up a
  • 00:04:10 little bit I recommend moving our
  • 00:04:14 variables into removing our arrays into
  • 00:04:17 variables so X is 1 2 3 and Y is 2 4 6
  • 00:04:25 and we can change now this to X Y and
  • 00:04:30 one thing that's annoying with the
  • 00:04:32 matplotlib if you're doing this in
  • 00:04:33 Jupiter notebook by default is you have
  • 00:04:34 this annoying little line here so you
  • 00:04:37 want to get rid of that you can just
  • 00:04:38 actually call plot dot show and that's
  • 00:04:42 the correct way to actually show this
  • 00:04:43 graph ok now that we have just a line on
  • 00:04:50 the screen let's start adding a little
  • 00:04:52 bit more to our graph so to do this
  • 00:04:55 let's go back to our documentation and
  • 00:04:57 go back to just the pie plot so I think
  • 00:05:01 this is a good spot to start because you
  • 00:05:03 always can kind of just control f and
  • 00:05:05 find something you're looking for so
  • 00:05:06 let's say we wanted to add a title to
  • 00:05:07 our graph if I type in title it points
  • 00:05:11 me right to a couple different places
  • 00:05:13 that I probably want to look at and
  • 00:05:15 right here is what we're looking for so
  • 00:05:17 set a title for the axes click that and
  • 00:05:21 this tells me all sorts of stuff about
  • 00:05:24 how I call this so it looks like I used
  • 00:05:27 to
  • 00:05:28 pie plot title so I can do plot title
  • 00:05:34 and let's just do our first graph and
  • 00:05:43 run that as you can see our title is now
  • 00:05:47 there and same thing for a lot of the
  • 00:05:51 different parameters so going back to
  • 00:05:55 the documentation if I want an X label
  • 00:05:58 on a white label I just type in right I
  • 00:06:01 guess I knew that but let's just say why
  • 00:06:05 I label nothing comes up Y or just even
  • 00:06:09 label C label label a contour plot
  • 00:06:12 that's not us the fig labels no I know
  • 00:06:17 title no X label Y label let's how we
  • 00:06:20 get there so you can keep doing this and
  • 00:06:24 really easily find what you're looking
  • 00:06:27 for I think it's a good place to go if
  • 00:06:29 you kind of just if you forget things
  • 00:06:32 because I always forget things in that
  • 00:06:34 plot lid
  • 00:06:34 okay so adding a label to x and y plus X
  • 00:06:39 label x axis and I guess I'm getting
  • 00:06:44 really enthusiastic because I keep
  • 00:06:46 adding exclamation points to all my
  • 00:06:48 stuff y axes yay see what happens
  • 00:06:54 yeah and I want to just get rid of these
  • 00:06:56 recommendations I don't need them okay
  • 00:06:57 so now we have a graph and we have a
  • 00:07:01 title and we have a y axis x axis in a
  • 00:07:06 real graph we would label these properly
  • 00:07:08 but for the sake of this example we're
  • 00:07:10 just kind of getting a feel for how we
  • 00:07:12 add these alright so now that we have
  • 00:07:14 our title and labels one thing we might
  • 00:07:16 want to do to them is resize them so if
  • 00:07:19 we look at the the documentation for
  • 00:07:23 title one thing you'll notice is that
  • 00:07:25 you can use you can pass in this font
  • 00:07:28 dictionary and it gives you a little bit
  • 00:07:30 of details about the Fondation area here
  • 00:07:32 but basically there's all sorts of
  • 00:07:34 options that we can do and like play
  • 00:07:36 around with our fonts so let's say I
  • 00:07:38 wanted to change the font of our title
  • 00:07:41 like a new font dict equals and I can
  • 00:07:43 pass in a font name and let's say I my
  • 00:07:49 good old trusty reliable comic sans ms
  • 00:07:53 will be our new font and if you look at
  • 00:07:57 that we got a nice new font on a graph
  • 00:08:01 and if you can't see it well then in
  • 00:08:04 that case I'll change the font size to
  • 00:08:07 be something like 20 now you should
  • 00:08:11 definitely be able to tell that I've
  • 00:08:13 changed the font type and in the
  • 00:08:17 description I listed I put a link to all
  • 00:08:19 the
  • 00:08:21 matplotlib fonts that you can use and if
  • 00:08:24 you look through the documentation you
  • 00:08:25 kind of find some different options you
  • 00:08:27 can do with this and you can also do the
  • 00:08:30 same thing with the labels I could do
  • 00:08:32 like font dict
  • 00:08:35 equals let's say I wanted to make this
  • 00:08:39 font arielle and that obviously might be
  • 00:08:43 the default but if I did it like Comic
  • 00:08:46 Sans as well you can tell that the
  • 00:08:50 x-axis now has changed but I want to
  • 00:08:53 just leave that this be for now okay so
  • 00:08:59 we did labels right so that one thing
  • 00:09:02 that's bothering me is the tick marks I
  • 00:09:04 want to let's say I just want to do
  • 00:09:05 integer numbers and I'm gonna add a
  • 00:09:08 couple more values to our graph so I'm
  • 00:09:10 gonna go to five I'm gonna start at zero
  • 00:09:13 and why would go from Y is always gonna
  • 00:09:17 be two times X so it's gonna look like
  • 00:09:21 that oh I would magically did it for us
  • 00:09:25 at that case I don't want it to
  • 00:09:30 magically do it for us okay let's say we
  • 00:09:32 went to four and we wanted just the
  • 00:09:35 integer values we didn't want any
  • 00:09:36 decimal value so how do we change our
  • 00:09:38 ticks so we can do that by doing plot X
  • 00:09:44 ticks and our X ticks will do 0 0 1 2 3
  • 00:09:50 and I also just found remember this
  • 00:09:52 command by using the documentation and
  • 00:09:54 our white ticks will be have a 0 to 10
  • 00:10:00 every two so it's 0 2 4 6 oh my gosh 10
  • 00:10:12 as you can see that now we have the tick
  • 00:10:16 marks working properly and maybe I
  • 00:10:18 wanted to add 4 as well so now we
  • 00:10:21 labeled our ticks differently and one
  • 00:10:24 thing that's cool to know is that the
  • 00:10:25 graph will automatically resize based on
  • 00:10:27 how we set this so if I set one tick to
  • 00:10:30 a thousand well now our graph kind of
  • 00:10:34 like not too good but it's nice that you
  • 00:10:38 can easily do that for is better but and
  • 00:10:44 you can do the same thing with why I'd
  • 00:10:45 say when do they make the last one 100
  • 00:10:48 as you can see it changes up the sizing
  • 00:10:52 of the graph one thing that's also cool
  • 00:10:54 though is find it even if I didn't even
  • 00:10:56 lis space these out if I did like seven
  • 00:10:58 here and then 7.5 as you can see it
  • 00:11:03 properly puts those at the right spot in
  • 00:11:06 the graph I'll leave it like this I'll
  • 00:11:10 leave it a little bit weird but yeah
  • 00:11:12 that looks good to me
  • 00:11:13 okay so we have our first graph let's uh
  • 00:11:16 add a legend and make this line a little
  • 00:11:19 bit more exciting color wise so if we
  • 00:11:22 wanted to add a legend we can do and I
  • 00:11:25 would actually kind of like showing how
  • 00:11:27 the documentation is helpful if I looked
  • 00:11:32 up legend
  • 00:11:33 Figg legend that might be work just this
  • 00:11:37 legend place a legend on the axes like
  • 00:11:41 by looking up legend I have figured out
  • 00:11:42 that the call is just legend and it
  • 00:11:45 gives me some examples so I always like
  • 00:11:47 to refer to this documentation okay so
  • 00:11:50 PLT dot legend and what happens when I
  • 00:11:54 do that no handles with labels fanned
  • 00:11:57 put in legends so it's complaining
  • 00:11:59 because we don't have anything to label
  • 00:12:01 what it's saying is how do we label this
  • 00:12:04 line and the way we do that is by
  • 00:12:07 passing in a label to our plot function
  • 00:12:10 so in this case our x and y we plotted X
  • 00:12:15 to be or Y to be 2 times X so I'm going
  • 00:12:17 to call the label here 2x and as you can
  • 00:12:21 see we get 2x right there okay let's say
  • 00:12:26 now that we wanted to change up the
  • 00:12:28 color of this line maybe make it thicker
  • 00:12:31 do some other things to it if we go to
  • 00:12:36 plot
  • 00:12:41 whereas plot will see all sorts of
  • 00:12:46 properties that we can do and plot so
  • 00:12:48 what I'm seeing right here is you can
  • 00:12:51 pass in all of these different
  • 00:12:53 parameters to our plot and it probably
  • 00:12:57 lists off what we can put maybe not it's
  • 00:13:00 not super specific but if you look hard
  • 00:13:03 enough you can see all these properties
  • 00:13:05 that you can pass into the plot function
  • 00:13:08 so one thing we could plot pass in is
  • 00:13:11 color so if I passed in color equals red
  • 00:13:20 will work and it will note I think the
  • 00:13:22 common color so if I did yellow if I did
  • 00:13:27 like yellow which is not a color it's
  • 00:13:29 gonna yell at me might even work with y
  • 00:13:31 yeah cool and we also can pass in
  • 00:13:34 hexadecimal colors so I could do like a
  • 00:13:37 b a b a b and we got like a grayish
  • 00:13:39 color you get this is helpful because
  • 00:13:42 you can pick use like a color picker
  • 00:13:44 tool and pick pretty much any color you
  • 00:13:47 want here but we'll stay with red for
  • 00:13:49 now the other parameters I could pass
  • 00:13:53 into that let's see what else we had I
  • 00:13:56 could do I think the line size equals
  • 00:14:01 let's say 12 oh that is not a prat
  • 00:14:04 parameter not remembered either go back
  • 00:14:09 to my documentation size marker size
  • 00:14:16 maybe that's it more precise oh I also
  • 00:14:20 see you lying with here so line width
  • 00:14:22 equals 2
  • 00:14:29 ohmygosh line with equals 12 makes this
  • 00:14:32 big line maybe two it's a bit bigger
  • 00:14:36 than I think what we had we can also do
  • 00:14:39 we can label a marker so let's say I
  • 00:14:42 wanted to add dots into this as you can
  • 00:14:46 see you can't really see it too too well
  • 00:14:48 for me if I made the marker size a
  • 00:14:50 little bit bigger and I'm just kind of
  • 00:14:53 passing this in so you could kind of see
  • 00:14:55 what you can do oh that didn't work
  • 00:14:57 let's say 10 yeah as you can see nicely
  • 00:15:00 big dots on my graph I can also do
  • 00:15:06 marker edge color there's all sorts of
  • 00:15:10 properties I'm just like continually
  • 00:15:12 passing these in but now you see a
  • 00:15:14 different type of dot and whatnot so
  • 00:15:18 this is pretty cool that we can have all
  • 00:15:20 this customization sometimes takes a
  • 00:15:22 little while to get what we want but
  • 00:15:24 it's usually it just is nice to have
  • 00:15:27 this power and one final thing I'll pass
  • 00:15:30 in is line style
  • 00:15:42 so there's all sorts of line styles we
  • 00:15:44 can pass it and you can read all into
  • 00:15:47 the different ways you can do this in
  • 00:15:49 the documentation one thing that's
  • 00:15:54 pretty cool
  • 00:15:55 is that instead of listing all of these
  • 00:15:57 keyword arguments sometimes we just want
  • 00:15:58 to make a different type of line quickly
  • 00:16:00 so there's actually a shorthand that you
  • 00:16:03 can use to kind of do pretty much the
  • 00:16:05 same thing
  • 00:16:06 so I comment this out real quick we have
  • 00:16:08 no graph what you can do is there's a
  • 00:16:12 shorthand notation that allows you to
  • 00:16:15 kind of have a pretty good amount of
  • 00:16:16 customization quickly so the shorthand
  • 00:16:21 notation is color marker line style I
  • 00:16:24 guess so if we go and copy this line
  • 00:16:27 from above let's say we just passed in
  • 00:16:34 this now what we can do is before we add
  • 00:16:43 our label we can pass in the shorthand
  • 00:16:46 notation so I can do color will say read
  • 00:16:49 it I think just accepts letters you can
  • 00:16:52 look into the documentation see exactly
  • 00:16:53 what it does marker will do a dot and
  • 00:16:56 then line will do a dash so watch what
  • 00:16:59 happens when I do this gives us nice
  • 00:17:03 line with dots in it if I do two dashes
  • 00:17:07 gives us the dotted line if I do like a
  • 00:17:10 different type of marker you can pass in
  • 00:17:13 like a caret like that gives us a line
  • 00:17:15 with carrots in it it's kind of cool
  • 00:17:17 that you can do this shorthand notation
  • 00:17:20 and get different types of lines very
  • 00:17:22 easily just to follow up on the whole
  • 00:17:25 shorthand notation pulling in the docs
  • 00:17:29 for the plot function it shows all the
  • 00:17:32 different markers you can use and the
  • 00:17:35 different line Styles supported and the
  • 00:17:36 different colors supported so check out
  • 00:17:39 the plot documentation to see all that
  • 00:17:43 all right let's move on to our next
  • 00:17:46 thing and that will be
  • 00:17:48 I guess let's just out another line real
  • 00:17:50 quick to our graph so we have our first
  • 00:17:53 line let's add line number two and this
  • 00:18:01 one will make a little bit more
  • 00:18:02 interesting and the thing is like here
  • 00:18:06 we had a very straightforward like you
  • 00:18:08 have X any other Y but this is not
  • 00:18:11 always easy to do especially if you have
  • 00:18:12 like a function like sign where you want
  • 00:18:15 to plot it at like a bunch of values but
  • 00:18:18 those values are all like you know crazy
  • 00:18:19 decimals so I'm gonna show you how you
  • 00:18:22 can handle something like that so this
  • 00:18:24 is where we use numpy so nobody call
  • 00:18:28 this x2 I'm gonna say that x2 equals NP
  • 00:18:31 a range 0 to 4 and we'll go by 0.5 as
  • 00:18:38 our tick so if I print out x2 real quick
  • 00:18:42 you see that this gives us a numpy array
  • 00:18:46 with zero 0.5 1 1.5 to 2.5 3 to 3.5 I'll
  • 00:18:52 actually make it good a 4.5 so it goes
  • 00:18:54 at the same spot as our other graph
  • 00:18:56 because this is a exclusive here so we
  • 00:18:59 have that so that's gonna be our exes
  • 00:19:04 and so what I can do here is I can go
  • 00:19:09 ahead and plot that and I'm going to
  • 00:19:12 plot the square function for it so I'm
  • 00:19:15 gonna pass in x2 and then instead of
  • 00:19:18 passing in a why I'm just gonna do x2
  • 00:19:20 and I'm gonna do squared what happens
  • 00:19:24 here so now you see we get x2 squared
  • 00:19:28 it goes a little bit higher than our
  • 00:19:30 original axis was set so I'm gonna
  • 00:19:32 change up the ticks or maybe I'll just
  • 00:19:34 kind of comment this out and see what
  • 00:19:36 happens for a tick marks yeah I'm fine
  • 00:19:38 with just leaving the default that it
  • 00:19:40 gave us looks good to me
  • 00:19:42 and now we have two blue colors so let's
  • 00:19:45 make this a different color maybe you
  • 00:19:48 make it red we want to give it a label
  • 00:19:51 as well so I'm going to do red I'm gonna
  • 00:19:54 say the label is equal to x-squared and
  • 00:20:02 one thing that's cool is that it
  • 00:20:03 automatically moved this legend to the
  • 00:20:05 top left because the positioning was
  • 00:20:07 better now that this goes up to the top
  • 00:20:10 right okay so we have two two lines up
  • 00:20:13 there and from the original image I
  • 00:20:15 showed there's some stuff that's still
  • 00:20:17 different one thing that's kind of cool
  • 00:20:20 that you could do is let's say you had a
  • 00:20:23 graph that stopped but you wanted to
  • 00:20:25 kind of show the projection of it not in
  • 00:20:27 the future so what I did to show that
  • 00:20:30 type of a phenomenon is I did like X to
  • 00:20:33 take the first four values here it'll
  • 00:20:40 plot that what did I do
  • 00:20:42 oh shoot first four so what I want I
  • 00:20:51 think that will work take the first
  • 00:20:56 floor and plot that and then for the
  • 00:20:59 last values so from let's say five or
  • 00:21:11 three are this make this a little bigger
  • 00:21:14 make this six or five
  • 00:21:23 bear with me here from four onward we'll
  • 00:21:29 make it a dash line and I had a little
  • 00:21:31 bit of overlap because I think they'll
  • 00:21:33 look better you'll see in a sec four –
  • 00:21:36 make this still the same function but
  • 00:21:40 this time we're gonna make it a dashed
  • 00:21:41 line so there you see and I'm gonna
  • 00:21:45 actually make this a little bit
  • 00:21:46 different there you see like maybe
  • 00:21:57 something ended here and then you make
  • 00:21:59 it – the rest of the way you could do
  • 00:22:01 something like that using the format I
  • 00:22:03 just showed all right what else do we
  • 00:22:07 have probably clean this code up a
  • 00:22:09 little bit another thing that I showed
  • 00:22:11 in the original graph that I showed when
  • 00:22:14 I was a introducing this video was a
  • 00:22:17 resize so let's say we wanted to resize
  • 00:22:20 our graph well we should do that by near
  • 00:22:22 the top of our graph so I'm going to go
  • 00:22:26 ahead and do resize your graph I'm going
  • 00:22:36 to go ahead and do plot figure pass in
  • 00:22:39 fig size and we're gonna say let's make
  • 00:22:42 the dimensions 5 by 3 it's kind of an
  • 00:22:46 arbitrary 5 by 3 that will give you kind
  • 00:22:49 of the ratio of your X to Y or Y but to
  • 00:22:52 specify how many pixels it is you're
  • 00:22:55 gonna want to pass in a second parameter
  • 00:22:57 which is dpi which basically is pixels
  • 00:22:59 per inch so I recommend using a value of
  • 00:23:03 around 300 here if you do smaller values
  • 00:23:07 you'll have more pixelated graphs so if
  • 00:23:10 you can afford having a bigger image
  • 00:23:12 having a bigger dpi is often nice so in
  • 00:23:16 this case we have pixels per inch of 300
  • 00:23:19 so this is going to actually be 5 inches
  • 00:23:21 by 3 inches so that Tolle pixels will be
  • 00:23:24 1500 by 900 here in this graph so now
  • 00:23:28 it's much much bigger maybe that's a
  • 00:23:31 little bit too big
  • 00:23:35 I didn't I'm gonna be blocking this
  • 00:23:37 graph so I'm gonna make it a little bit
  • 00:23:39 smaller but you get the idea then here
  • 00:23:45 so we'll make it like two by 1.5 that's
  • 00:23:52 not a good dimensions now though I mean
  • 00:23:57 just play around with this the the
  • 00:24:01 biggest issue I have right now is the
  • 00:24:02 graph looks so big because I have my
  • 00:24:06 screen super-high resolution or super
  • 00:24:09 the view is like very up close because I
  • 00:24:13 want to make sure you guys and see my
  • 00:24:14 code but yeah this would be a 1500 by
  • 00:24:18 900 graph I'm gonna just for the sake of
  • 00:24:22 the graph decrease the DPI and make it
  • 00:24:26 more reasonable that the issue you can't
  • 00:24:29 really tell from this image but if you
  • 00:24:31 really zoom into the graph and maybe if
  • 00:24:33 you like printed the graph out it would
  • 00:24:36 look maybe a little bit pixelated with a
  • 00:24:38 dpi of 100 so probably try to keep this
  • 00:24:42 value higher if possible and then
  • 00:24:46 another thing you want to do is you'll
  • 00:24:52 want to save your graph so to say we can
  • 00:24:55 do plot dot savefig and when you do say
  • 00:25:08 buy graph dot PNG and one thing that's
  • 00:25:12 nice too is like it passing the DPI
  • 00:25:15 parameter here as well so let's say when
  • 00:25:19 I actually see if my graph wanted to be
  • 00:25:20 bigger but for the sake of being able to
  • 00:25:22 show you guys it in a smaller format I
  • 00:25:24 wanted the 100 above I can still go
  • 00:25:28 ahead and save it with 300 and then kind
  • 00:25:31 of solves both of my problems and so
  • 00:25:34 this then my graph top P&G will save in
  • 00:25:37 the current directory that this MATLAB
  • 00:25:39 matplotlib tutorial is in it was yeah
  • 00:25:43 well saving that current the current
  • 00:25:44 directory what ever fought whatever
  • 00:25:46 directory your file not
  • 00:25:47 lib tutorial as in this graph will also
  • 00:25:49 save there when we run this cool now we
  • 00:25:53 have that saved all right let me clean
  • 00:25:58 this up a little bit
  • 00:26:17 and just to note the reason I did this
  • 00:26:19 is because this is exclusive the six
  • 00:26:21 here so when I do five onwards it picks
  • 00:26:25 up this actually ends at five because it
  • 00:26:28 doesn't include six so it actually
  • 00:26:30 covers everything here
  • 00:26:59 all right now that we've shown line
  • 00:27:02 graphs a bit let's go and do quickly do
  • 00:27:05 bar charts and after bar charts I think
  • 00:27:08 we're going to just end this video short
  • 00:27:10 and I'll do the real-world examples in a
  • 00:27:11 video that I'll post next week I just
  • 00:27:14 think this video might get a bit too
  • 00:27:16 long if I include everything in just one
  • 00:27:18 video so all right so I want to do bar
  • 00:27:21 chart
  • 00:27:28 okay so bar charts are pretty straight
  • 00:27:31 for it as well let's say we had some
  • 00:27:33 labels a a B and C and some values that
  • 00:27:45 say 1 4 & 2
  • 00:27:49 well if we wanted to do a bar chart
  • 00:27:51 where you just do plot dot bar of labels
  • 00:27:55 comma values at Friday they're wrong
  • 00:27:58 it's values comma labels and we get not
  • 00:28:05 what I was looking for okay let's see it
  • 00:28:11 is actually labels first then values ABC
  • 00:28:19 cool so that was pretty straightforward
  • 00:28:21 and I can do the plot touch show we're
  • 00:28:26 gonna do all the adding of titles and
  • 00:28:29 whatnot the same way as before in the
  • 00:28:31 line graph example let's skip over that
  • 00:28:34 for now
  • 00:28:36 it could also resize it let's say so I
  • 00:28:38 could do plot figure fig size equals
  • 00:28:44 it's a six by four it's gonna use
  • 00:28:48 whatever the default dpi is and then one
  • 00:28:51 thing that it's cool that you can do
  • 00:28:52 with bar charts is you could add
  • 00:28:57 different patterns to these so to do
  • 00:29:00 that and you can you can really play
  • 00:29:03 around with the documentation do all
  • 00:29:04 sorts of different
  • 00:29:06 I do some kind of following the graphs
  • 00:29:09 that I was showing the inner intro of my
  • 00:29:11 video so I wanted to just show kind of
  • 00:29:13 what different hash values look like so
  • 00:29:18 I can make first one have gonna say bars
  • 00:29:24 equal plug up ours there you go
  • 00:29:27 now I do bars zero set hatch that's
  • 00:29:31 gonna give me the lines that you see
  • 00:29:33 down here I can do the same thing with
  • 00:29:36 the second value let's make this circles
  • 00:29:43 and you can find all the hatch values in
  • 00:29:47 the documentation as well let's do the
  • 00:29:50 third value we'll do stars so now you
  • 00:29:53 get kind of a cool little bar chart I
  • 00:29:56 can also add a legend to this very
  • 00:29:58 easily and this will tell me right away
  • 00:30:00 we have a B and C but I mean their label
  • 00:30:02 right here some legends probably not
  • 00:30:04 necessary in this case alright let's see
  • 00:30:09 what else do I want to do with this and
  • 00:30:10 then if you wanted to make this a little
  • 00:30:12 bit neater if you had like many more I
  • 00:30:14 might get tiring to do this so you could
  • 00:30:16 do something like patterns equals /o and
  • 00:30:24 star and you could do instead of this
  • 00:30:29 notation you could do yeah for a bar and
  • 00:30:35 Baris bar dot set patch I guess we want
  • 00:30:44 an index as well
  • 00:30:50 we'll just do actually patterns dot pop
  • 00:30:54 first item off so this would get us our
  • 00:30:58 right one for each one should yeah look
  • 00:31:00 at that if I didn't pop regular I think
  • 00:31:05 it would take off the last so this will
  • 00:31:06 be stars instead of yep look at that
  • 00:31:10 yeah so basically what it did is it just
  • 00:31:12 popped off the first item for the first
  • 00:31:14 bar popped up the second item for the
  • 00:31:15 second bar and then popped off the final
  • 00:31:17 item for the third bar as you can see
  • 00:31:20 there so that's bar charts really
  • 00:31:23 quickly I think I'm going to end this
  • 00:31:25 video here at this the the real-world
  • 00:31:28 examples video will be very very useful
  • 00:31:30 and I'll post that next week I just want
  • 00:31:33 to like make this video too too long let
  • 00:31:37 me know your feedback hopefully this
  • 00:31:38 helped you a bit I'm happy to be back
  • 00:31:42 happy to be making videos just just
  • 00:31:44 trying to ease back into it with this if
  • 00:31:47 you enjoy this video make sure to throw
  • 00:31:48 a big thumbs up and subscribe if you
  • 00:31:52 don't mind yeah but yeah look look out
  • 00:31:56 for the real world examples video I'll