Coding

Python Plotting Tutorial w/ Matplotlib & Pandas (Line Graph, Histogram, Pie Chart, Box & Whiskers)

  • 00:00:00 what's up guys welcome back to another
  • 00:00:01 video now that I'm a little bit more
  • 00:00:03 free trying to grind these out pretty
  • 00:00:05 quickly so happy to be back again with
  • 00:00:08 another video in this video we're going
  • 00:00:10 to build off of what we didn't in the
  • 00:00:11 last video which was kind of an
  • 00:00:12 introductory video to Matt pot Lib
  • 00:00:15 library of Python so in this video
  • 00:00:17 specifically we're going to be kind of
  • 00:00:18 doing some real world type examples so
  • 00:00:21 basically combining our knowledge of the
  • 00:00:23 pandas library with the matplotlib
  • 00:00:25 library to create all sorts of different
  • 00:00:27 plots based on CSV style data so we'll
  • 00:00:31 start out with a spreadsheet that I'll
  • 00:00:35 provide on my github page link in the
  • 00:00:37 description to gas prices over time for
  • 00:00:43 different countries so with that data
  • 00:00:45 sheet will build charts such as the one
  • 00:00:48 you see here then the second data set
  • 00:00:52 that I provided is a list of all the
  • 00:00:54 game the video game FIFA's player stats
  • 00:00:58 so if you're not familiar with that and
  • 00:01:00 basically all of the soccer players or I
  • 00:01:02 guess if you're an international viewer
  • 00:01:03 watching this all the football players
  • 00:01:05 in the game FIFA provided all their like
  • 00:01:08 overall stats in the game and will build
  • 00:01:10 grab all sorts of charts off of that so
  • 00:01:13 we'll do like histogram stuff with
  • 00:01:15 players overall rating in FIFA some pie
  • 00:01:19 chart stuff more pie chart stuff a
  • 00:01:23 little bit more complex and then finally
  • 00:01:25 some box and whisker chart stuff based
  • 00:01:28 off the FIFA data and if we have time
  • 00:01:30 maybe one or two more graphs before we
  • 00:01:34 begin couple quick
  • 00:01:36 I guess announcements first is if you've
  • 00:01:39 enjoyed any of my videos it'd mean a lot
  • 00:01:40 to me if you can subscribe and also
  • 00:01:43 along the same lines if you don't mind
  • 00:01:45 also following my Instagram and Twitter
  • 00:01:48 basically the more followers I get on
  • 00:01:51 all my social media platforms the more
  • 00:01:53 content the more serious that I'll take
  • 00:01:56 this and the more content that I'll
  • 00:01:59 produce and then the other thing is do
  • 00:02:03 not forget to root for the Bruins
  • 00:02:05 tonight I don't actually know what I'm
  • 00:02:07 going to post this video but
  • 00:02:09 as I'm making this video they are about
  • 00:02:10 to go into Game four of the Stanley Cup
  • 00:02:12 Finals so really hoping they can pull
  • 00:02:15 out a W and hope that this video ages
  • 00:02:18 well alright let's get into it
  • 00:02:21 alright we'll start this video off the
  • 00:02:23 same way we started the last video make
  • 00:02:24 sure you load up the necessary libraries
  • 00:02:26 I'll be editing with Jupiter notebook
  • 00:02:29 using Python 3 but you can be using
  • 00:02:31 other IDs and text editors as well so
  • 00:02:35 we're importing these three libraries
  • 00:02:36 matplotlib numpy and pandas then the
  • 00:02:40 next step will be to download the data
  • 00:02:42 that I provided for this so to do that
  • 00:02:45 go to my github which is in the
  • 00:02:47 description and we want to download two
  • 00:02:49 different files so the files the first
  • 00:02:52 file we want to download is this gas
  • 00:02:54 prices so the easiest way to think to
  • 00:02:56 download this is go to the raw and then
  • 00:02:59 just do save as you can and you want to
  • 00:03:04 save it wherever you have your code so
  • 00:03:08 my code these Jupiter notebooks for me
  • 00:03:11 are in this matte pot Lib tutorial
  • 00:03:13 directory so I would save this value
  • 00:03:16 here as you see I already saved it and
  • 00:03:18 then for the the other data file the
  • 00:03:21 FIFA dataset we're gonna want to do the
  • 00:03:23 same thing so go back to the main file
  • 00:03:25 in the github click on FIFA data this
  • 00:03:28 one you can even preview but just click
  • 00:03:30 view raw right click and save as you
  • 00:03:35 want to save it as a CSV file so a comma
  • 00:03:39 separated values file and you'll also
  • 00:03:41 want to save this in the same directory
  • 00:03:43 that you have the file that you're
  • 00:03:44 writing your code in okay so now that
  • 00:03:49 we've saved the data let's start playing
  • 00:03:51 around with it and if you remember from
  • 00:03:53 my pandas video the way that we can look
  • 00:03:57 at a CSV file with pandas is we can do
  • 00:04:00 something like we'll call this C us or
  • 00:04:02 we'll call our data gasps equals PD read
  • 00:04:06 CSV then we need to type in the name of
  • 00:04:09 the file we want to read we've saved it
  • 00:04:11 as gas prices dot CSV and we should be
  • 00:04:14 alert on that no issues and we saved
  • 00:04:18 this file in the same directory that
  • 00:04:19 this map pot lived
  • 00:04:21 realism so that's why this worked if you
  • 00:04:24 save this file in a different directory
  • 00:04:26 you can specify where you save it so you
  • 00:04:29 save it in like a data folder you would
  • 00:04:32 specify it so with this type of syntax
  • 00:04:35 okay yes so now what we can do is look
  • 00:04:38 what to see what's in our this data file
  • 00:04:42 so if I just do gas and this works in
  • 00:04:45 Jupiter notebook but in another if
  • 00:04:49 you're just using like sublime text you
  • 00:04:51 have to like print gas or you could just
  • 00:04:54 be looking at the actual CSV file and
  • 00:04:56 like Excel so gas we have year and then
  • 00:05:02 we have all these different countries
  • 00:05:03 and their price and US dollars per
  • 00:05:06 gallon for gas that year so the way I
  • 00:05:10 look at this we're gonna have year as
  • 00:05:12 our x input so ah stop texting me so
  • 00:05:18 based on the year each country has a
  • 00:05:21 different gas price so the way we can
  • 00:05:26 access that is we can do something like
  • 00:05:28 PLT dot plot and so our X data is going
  • 00:05:34 to be gas a year our Y data is gonna be
  • 00:05:40 let's say we start with USA so USA is
  • 00:05:43 all caps here so I have to follow that
  • 00:05:45 same syntax when I'm accessing that gas
  • 00:05:47 that USA and then I can do a plot dot
  • 00:05:51 show and I think already there will have
  • 00:05:54 a basic graph up and running so as you
  • 00:05:56 can see yep this is the basic graph for
  • 00:06:01 our data and we could also add another
  • 00:06:04 country we can do plot plot let's add
  • 00:06:07 Canada year Gast Canada I think yeah as
  • 00:06:17 you can see now we have two different
  • 00:06:18 graphs and as you can see from this it's
  • 00:06:21 easy to see more easily than just
  • 00:06:23 reading the CSV that oh okay
  • 00:06:25 every year gas and Canada is
  • 00:06:27 consistently higher than in the USA but
  • 00:06:31 we have some problems with this guy
  • 00:06:33 so like one thing that I see that's an
  • 00:06:35 issue is all these years like I don't
  • 00:06:38 know I think it just makes more sense to
  • 00:06:40 be looking at the exact year especially
  • 00:06:42 since this data wasn't like broken up by
  • 00:06:44 month so like I don't like the x axis
  • 00:06:47 labels we have no title we have no real
  • 00:06:50 good indicator of what these values mean
  • 00:06:53 over here on the y axis so we need to
  • 00:06:56 start fixing some things up and quickly
  • 00:06:58 to know if you have like a multi-word
  • 00:07:00 name this format of dot year probably
  • 00:07:03 won't work so you can also do bracket
  • 00:07:08 notation to access that field as you see
  • 00:07:11 it still works so if we had something
  • 00:07:13 with two names and I don't remember let
  • 00:07:15 me look at the data again see if any
  • 00:07:17 countries have that South Korea for
  • 00:07:23 example like we would have to use this
  • 00:07:25 syntax so I'll actually plot South
  • 00:07:28 Korea's gas in this list their gas
  • 00:07:33 prices so plot plot gas year gas South
  • 00:07:43 Korea wouldn't work maybe actually it
  • 00:07:45 would work with the underlines I'm not
  • 00:07:47 sure yeah South Korea's having issues so
  • 00:07:50 what we can do is south space Korea now
  • 00:07:56 we have three lines and Wow
  • 00:07:57 yeah the gas in South Korea is even more
  • 00:07:59 expensive okay it's just kind of
  • 00:08:01 bothering me mixing these different ways
  • 00:08:04 to do this so I'm going to change this
  • 00:08:05 back to here change this back to year
  • 00:08:08 and only leave South Korea like that
  • 00:08:11 because it has to be like that okay so
  • 00:08:13 now we have some plots let's make this
  • 00:08:15 graph overall better though so to start
  • 00:08:18 let's add a title so that a title if you
  • 00:08:22 remember from my last video and feel
  • 00:08:24 free to review that again we can just
  • 00:08:26 use peel detail I can label this like
  • 00:08:31 gas prices over time
  • 00:08:39 in u.s. dollars and so it still doesn't
  • 00:08:44 make too much sense because you see all
  • 00:08:47 these lines but you don't know what they
  • 00:08:48 represent I mean we only know that what
  • 00:08:50 they represent because we see the code
  • 00:08:52 here but we should add a legend and so
  • 00:08:55 to add a legend we're not to first give
  • 00:08:58 these plots labels because if I don't
  • 00:08:59 give these labels watch what happens
  • 00:09:01 plot dot legend oh wow it worked I was
  • 00:09:10 not actually expecting that to work try
  • 00:09:16 to think why that is that it worked
  • 00:09:17 whatever it worked without needing to
  • 00:09:20 add the labels specifically so that's
  • 00:09:23 kind of nice for us I guess due to the
  • 00:09:25 fact that we're reading this in and we
  • 00:09:28 kind of from a nice CSV that already has
  • 00:09:31 headers it probably worked but in our
  • 00:09:33 last video you had to add label so I
  • 00:09:38 could actually change the label if I
  • 00:09:40 wanted to if I wanted this to just say
  • 00:09:41 United States see that change it like
  • 00:09:46 that so you can add this optional label
  • 00:09:49 parameter if things aren't working for
  • 00:09:50 you properly but for us it just kind of
  • 00:09:53 magically did the trick okay so this is
  • 00:09:56 looking already a little bit better I
  • 00:09:58 might make the graph a little bit bigger
  • 00:10:00 let's do that I can do plot dot figure
  • 00:10:05 big size equals say 8 by 5 so now that's
  • 00:10:12 a nicer size and it's more easy to see
  • 00:10:15 everything the legend is a more
  • 00:10:17 reasonable size and comparison of
  • 00:10:20 everything in there so that's bit better
  • 00:10:23 what else can we do to this well we
  • 00:10:26 don't have any labels for axes so we
  • 00:10:28 should definitely do that also I really
  • 00:10:30 don't like that these tick marks are not
  • 00:10:31 exact years so I think the next thing
  • 00:10:34 I'm going to do is change up the ticks
  • 00:10:36 so X ticks what we can pass in is just
  • 00:10:43 the year here so now it will have a tick
  • 00:10:46 for every year that we have data for Wow
  • 00:10:50 and that looks
  • 00:10:51 solutely fantastic yeah obviously issues
  • 00:10:55 with this too squished together so what
  • 00:10:58 can work well is if I print out gas that
  • 00:11:03 year you see we have part of a panda's
  • 00:11:07 data frame but we have over one of these
  • 00:11:09 years if we remember you know some
  • 00:11:13 google list
  • 00:11:15 compris and not list comprehension the
  • 00:11:18 list iterating syntax maybe that will be
  • 00:11:22 the word but you know when you want to
  • 00:11:25 get certain items like the first five
  • 00:11:26 items in a list you go zero to five or
  • 00:11:30 you could even just do five what we want
  • 00:11:32 to do is iterate you know maybe take
  • 00:11:34 every three years so what we could do to
  • 00:11:37 do that is we don't care where we start
  • 00:11:38 it so we're gonna start at the beginning
  • 00:11:39 we want to end at the end but we want to
  • 00:11:42 skip every three years so now we get all
  • 00:11:45 the years in a we get every third year
  • 00:11:51 which will probably be better when we
  • 00:11:52 graph it down here so I'm gonna do that
  • 00:11:55 now so guess year tick tick
  • 00:11:57 three colon colon three cool that looks
  • 00:12:01 pretty good all right
  • 00:12:06 I also kind of would like to have exact
  • 00:12:10 values here kind of show exactly where
  • 00:12:13 we're plotting the points so to do that
  • 00:12:16 if you remember the shorthand notation
  • 00:12:18 from the last video we can do stuff like
  • 00:12:22 will make us a blue dot
  • 00:12:30 – so blue is the color and we want to
  • 00:12:33 dot – we want dot markers and a – a
  • 00:12:38 straight line
  • 00:12:39 it's basically what we're saying cool so
  • 00:12:42 now we have every third year but we have
  • 00:12:44 points for every time we actually have a
  • 00:12:46 data
  • 00:12:47 so that looks good we do the same thing
  • 00:12:50 for the other ones red – and what's cool
  • 00:12:56 – is you see that the legend changes as
  • 00:12:58 we do that
  • 00:12:59 South Korea let's say green dot – cool I
  • 00:13:08 like the look of this still we need to
  • 00:13:11 do some more modifications let's add
  • 00:13:13 labels to our X and y-axis so X label
  • 00:13:19 will be year that's pretty
  • 00:13:22 self-explanatory then the Y label will
  • 00:13:29 be US dollars cool so now you can see
  • 00:13:42 you know okay and year 2008 South Korea
  • 00:13:47 paid approximately $6 per gallon of gas
  • 00:13:53 we're all translating all these values
  • 00:13:55 to US dollars while Canada paid about
  • 00:13:58 four dollars and the u.s. played about
  • 00:14:03 three dollars so that looks pretty good
  • 00:14:08 to me and we can easily add some more
  • 00:14:13 countries here so I could like add
  • 00:14:17 Australia for example and we'll make
  • 00:14:22 them ah I don't know what color to use I
  • 00:14:27 don't know that any more yellow sure I
  • 00:14:30 may be ugly color yeah it's not too bad
  • 00:14:33 but yeah and there we have Australia
  • 00:14:35 looks like they're missing maybe a data
  • 00:14:37 value for 1990 I'm not positive but yeah
  • 00:14:41 we can easily do this for all of our
  • 00:14:43 different graphs and we could even do
  • 00:14:44 something like let's comment this out
  • 00:14:47 temporarily let me do something like for
  • 00:14:51 Country Inn
  • 00:14:55 gasps let's see what happens at that
  • 00:14:58 print country yeah cool this is giving
  • 00:15:03 us all the different countries we don't
  • 00:15:06 want year so I'm gonna say in gas one
  • 00:15:11 onwards now we have oh no close close
  • 00:15:23 close okay I'm gonna be a little bit
  • 00:15:26 hacky here if country is not equal to
  • 00:15:30 Year print country now we get all of the
  • 00:15:37 countries and so what we could do with
  • 00:15:38 this now is you know there's probable
  • 00:15:42 need of a way to do this then if country
  • 00:15:43 is not equal to year but I'm just trying
  • 00:15:47 to show you how like we could do this
  • 00:15:48 very quick and efficiently dude gas that
  • 00:15:51 year and then country and we'll let it
  • 00:15:55 self select the colors but we could if
  • 00:15:58 we wanted to specify marker equals dot
  • 00:16:01 and think the line style will be fine
  • 00:16:04 already
  • 00:16:04 oh no unrecognized character and oh okay
  • 00:16:13 can't just do country we need to do gas
  • 00:16:17 country look at that now we got all the
  • 00:16:23 different all the different countries in
  • 00:16:27 our graph and you could move there's
  • 00:16:31 ways within matplotlib to like move the
  • 00:16:33 legend outside of the graph I'm not
  • 00:16:36 going to go into that right now but
  • 00:16:38 another I guess comment that I have is
  • 00:16:40 whatever you're doing anything with
  • 00:16:42 matplotlib or anything with Python in
  • 00:16:44 general is like quickly do a google
  • 00:16:46 search like how to move legend outside
  • 00:16:48 of matplotlib graph and you'll find
  • 00:16:51 probably on Stack Overflow within the
  • 00:16:54 first three searches someone that had
  • 00:16:56 the same problem as you and found an
  • 00:16:58 answer to it so I always recommend
  • 00:17:00 that but this is kind of cool that we
  • 00:17:02 were able to quickly graph all these
  • 00:17:05 different lines for all the different
  • 00:17:06 countries and if you wanted to you could
  • 00:17:09 like create a list like countries to
  • 00:17:15 look at maybe out the best name and you
  • 00:17:18 could choose exactly which ones you
  • 00:17:20 wanted to include and then you would do
  • 00:17:22 if not equals a year and actually you
  • 00:17:25 could just do if country in countries to
  • 00:17:29 look at maybe they'll do this real quick
  • 00:17:42 if country in countries to look at so
  • 00:17:52 you see this is another way we can graph
  • 00:17:53 specific things cool cool cool all right
  • 00:17:57 I'm gonna comment this out temporarily
  • 00:17:59 and just leave I'll leave it I'll push
  • 00:18:05 it to the github when we're done with
  • 00:18:06 this video
  • 00:18:12 and one come with this again cool and
  • 00:18:21 yeah you can play around with this style
  • 00:18:23 you can use the shorthand notation or
  • 00:18:25 you can use the long hand notation that
  • 00:18:27 we kind of used here but you also can
  • 00:18:29 reference the first video I posted on
  • 00:18:31 matplotlib to really play around with
  • 00:18:33 your line graph styles alright we're
  • 00:18:36 pretty much done with this graph but a
  • 00:18:37 lot of a couple final things before I
  • 00:18:38 move on to the FIFA data and doing some
  • 00:18:41 other graphs so the first thing is
  • 00:18:43 changing up the font size I mentioned
  • 00:18:45 this in the previous mat plot lib video
  • 00:18:48 I did but I thought I was worth
  • 00:18:50 mentioning again so we can add a font
  • 00:18:52 stick to our title and actually we can
  • 00:18:54 add this to any text based label so you
  • 00:18:56 also add it to the excel a blue and
  • 00:18:58 white label and we can do all sorts of
  • 00:19:01 different tweaks to our font I put a
  • 00:19:04 list in the description to all the
  • 00:19:06 different fonts you can use here if you
  • 00:19:08 wanted to change up the actual font type
  • 00:19:10 but I'm going to keep the font type the
  • 00:19:12 same I'm going to change the font weight
  • 00:19:15 I'm gonna make it bold so you see it now
  • 00:19:18 it's not bold but if I do this watch
  • 00:19:21 what happens now it's bold and let's say
  • 00:19:24 I also wanted to change the font size I
  • 00:19:26 would say font size and let's say it's
  • 00:19:29 size 22 so now we have a larger font
  • 00:19:33 maybe 18 is a better value so we can do
  • 00:19:39 that you can do that for any of your
  • 00:19:40 your labels another thing we might want
  • 00:19:43 to do is in the when I showed this graph
  • 00:19:46 originally I also added the year 2011 we
  • 00:19:49 don't have values for 2011 but maybe you
  • 00:19:52 wanted to allow for the ability of that
  • 00:19:54 showing up and maybe project where
  • 00:19:56 they're going you could do Plus you take
  • 00:20:00 your ticks and plus 2011 ah that did not
  • 00:20:05 work so this is a litter this is a data
  • 00:20:10 frame so we can't just directly add 2011
  • 00:20:12 so we need to make it a list still
  • 00:20:16 didn't work and the problem is the data
  • 00:20:18 frame is kind of weird when you add just
  • 00:20:20 a direct list so you can do dot to list
  • 00:20:24 now do this now you see 2011 is there
  • 00:20:27 and then if you wanted to actually save
  • 00:20:30 this graph remember we can do plot dot
  • 00:20:32 save fig we can give it a name so gas
  • 00:20:37 price figure sure and remember when
  • 00:20:41 we're saving if you change the DPI
  • 00:20:43 you'll get a higher resolution image so
  • 00:20:46 300 is a good value this is gonna make a
  • 00:20:48 pretty big image she's gonna make a 300
  • 00:20:51 times eight which is 24 hundred by 1,500
  • 00:20:54 image but so really you can play around
  • 00:20:57 with this video but the higher the
  • 00:20:59 resolution or higher dpi the higher
  • 00:21:02 resolution image you're going to get so
  • 00:21:03 oh I want to say this is a PNG so if I
  • 00:21:08 went into that folder that I had as you
  • 00:21:12 can see where did it go refresh oh I
  • 00:21:17 don't know where I'm saving this just
  • 00:21:20 price figure where are you alright sorry
  • 00:21:23 I tipped this in wrong savefig and you
  • 00:21:27 always just you can refresh and look at
  • 00:21:29 the documentation I'm gonna become yeah
  • 00:21:31 I got an error here I should have
  • 00:21:32 noticed that before but yeah savefig one
  • 00:21:34 word do that now if I go to the folder
  • 00:21:39 that I have these files in we got the
  • 00:21:41 gas price figure and if I bring that in
  • 00:21:46 you see the figure they're saved nicely
  • 00:21:50 as a PNG alright let's move on to the
  • 00:21:54 FIFA data now that we're done with the
  • 00:21:56 gas price stuff let's move on to using
  • 00:21:59 our FIFA data so we're gonna first gonna
  • 00:22:01 have to load it in so in if you didn't
  • 00:22:06 save the FIFA data maybe just skipped
  • 00:22:08 around this video it's on my github page
  • 00:22:12 and the link to that is in the
  • 00:22:14 description and you want to save it in
  • 00:22:16 the same directory of the file that
  • 00:22:18 you're using to produce these graphs Lou
  • 00:22:21 I'm mixing my words the load FIFA data
  • 00:22:25 ok so to do that we'll just call FIFA
  • 00:22:28 equals PD read CSV
  • 00:22:33 and I believe we called this FIFA data
  • 00:22:36 dot CSV and that's just check make sure
  • 00:22:40 it's loaded in properly cool and this is
  • 00:22:42 actually shoot HUD shouldn't have loaded
  • 00:22:44 at all okay it's still a preview but you
  • 00:22:47 could do something if you only wanted to
  • 00:22:48 see like the first five rows you knew
  • 00:22:49 fifa that had five all right so so you
  • 00:22:54 can get a feel for what's in this data
  • 00:22:57 you got like the name of the player and
  • 00:22:59 you should probably recognize some of
  • 00:23:00 these guys names Leo Messi Ronaldo
  • 00:23:03 Neymar all very good players I think
  • 00:23:08 it's right now sorted probably by their
  • 00:23:10 overall but yet all the stats from the
  • 00:23:14 game FIFA for these guys and I think it
  • 00:23:15 just provides a good set of data to work
  • 00:23:19 from and also I took this data from a
  • 00:23:22 cattle challenge I'm gonna link to the
  • 00:23:24 original source of the data as well down
  • 00:23:27 the description ok so what can we do
  • 00:23:29 with this so to start off let's do some
  • 00:23:33 histogram stuff
  • 00:23:41 okay so what I think is cool first thing
  • 00:23:44 to do is plot the overall skill level
  • 00:23:46 here that you see on the right just
  • 00:23:50 figure out in the game like how many
  • 00:23:52 people have above a 90 how many people
  • 00:23:54 have between an 80 and 90 etc so what we
  • 00:23:57 can do to do that is we have our data
  • 00:23:59 already loaded I don't have to reload a
  • 00:24:01 10 but I can go ahead and do let's see
  • 00:24:09 plot and the way that I remember these
  • 00:24:13 commands is like I showed in the last
  • 00:24:15 video you can kind of use the PI plot
  • 00:24:19 documentation as your kind of your
  • 00:24:21 starting point and then if you're
  • 00:24:24 looking to try to do a histogram lookup
  • 00:24:26 histogram within that documentation link
  • 00:24:29 to the documentation is in the
  • 00:24:30 description and you'll find the command
  • 00:24:32 hist so what I can pass into history to
  • 00:24:37 set we're going to pass in the overall
  • 00:24:40 skill level as my input and let's see
  • 00:24:47 what happened going to do that and then
  • 00:24:49 I'll do a plot Dutch show so I don't get
  • 00:24:52 all this random stuff okay that looks
  • 00:24:55 pretty good it's already starting to get
  • 00:24:57 there what would probably be more
  • 00:25:00 helpful is if this kind of these tick
  • 00:25:05 marks were centered for each bin that we
  • 00:25:08 have and I'll do that in a sec all right
  • 00:25:12 we're gonna set the bins every 10
  • 00:25:16 overall skill level points so like the
  • 00:25:18 highest you would be and the FIFA game
  • 00:25:20 is 100 the lowest you could be as a zero
  • 00:25:22 so we'll do our bins at intervals of 10
  • 00:25:26 up to from 0 to 100 so the first bin
  • 00:25:30 that we have will be all players that
  • 00:25:32 have a skill level between 0 and 10 and
  • 00:25:34 it's counting that number 50 60 70 80 90
  • 00:25:41 and then finally 100 cool so oh I
  • 00:25:46 couldn't do anything yet now we can set
  • 00:25:49 the bins parameter of the the histogram
  • 00:25:53 to our bins now we got a nice a little
  • 00:25:58 bit nicer of a graph now the next thing
  • 00:26:01 I'm going to do is set our x ticks to be
  • 00:26:04 the bins as well so now it's nicely
  • 00:26:07 labeled each interval corresponds
  • 00:26:11 exactly with what we have here but it
  • 00:26:14 looks like we have some unnecessary data
  • 00:26:17 so it looks like there's very little
  • 00:26:19 players over here so maybe I'll limit
  • 00:26:22 this start at 40 and go up to 100 and
  • 00:26:28 what's kind of crazy is you know the
  • 00:26:33 players that are over a 90 are really a
  • 00:26:36 rarity because you can't even see that
  • 00:26:38 bar from the 90 to 100 range there so
  • 00:26:46 let's do a little bit get out of title
  • 00:26:49 the same way as before get out a while a
  • 00:26:51 ball so I'll do a lot Y they were real
  • 00:26:54 quick number of players and the X label
  • 00:27:00 would be the skill level then we could
  • 00:27:07 have a title that would be like
  • 00:27:10 distribution of player skills in in FIFA
  • 00:27:18 I think it's FIFA 2018 might be 2019 not
  • 00:27:23 positive so that's a cool little
  • 00:27:26 visualization and you can get more into
  • 00:27:30 details like to actually see that there
  • 00:27:32 are some values there you could do you
  • 00:27:38 change up your white X to be let's say 0
  • 00:27:44 to 100 okay that didn't work
  • 00:28:00 yeah yes it's kind of tough with all of
  • 00:28:05 these players but if we did move it from
  • 00:28:07 like 80 to 100 you see that yeah there
  • 00:28:11 are actually players that are above a 90
  • 00:28:13 is just very very few compared to the
  • 00:28:16 amount of players in the game another
  • 00:28:18 thing you could potentially do is maybe
  • 00:28:19 break it up use the data and only look
  • 00:28:24 at the stats of players and certain
  • 00:28:26 teams and then you wouldn't get all the
  • 00:28:27 noise I guess in the lower skill levels
  • 00:28:31 that I put all the people in here one
  • 00:28:35 little modification we can make to this
  • 00:28:37 is let's say we wanted to change the
  • 00:28:39 color of our bar I could set this you
  • 00:28:43 know I could set it to red easily like
  • 00:28:44 that or I could set it to a hexadecimal
  • 00:28:47 value very easily and what I recommend
  • 00:28:52 whatever you want a certain color what
  • 00:28:55 you can do is just like do a google
  • 00:28:57 search for a color picker as you see
  • 00:29:00 here I can just move this bar around and
  • 00:29:05 no matter what color it wants so let's
  • 00:29:07 say I want this greenish color I copy
  • 00:29:09 that hex code hide this paste in the hex
  • 00:29:14 code now I get that green color I kind
  • 00:29:18 of like the bluish color so I'm gonna go
  • 00:29:21 with that but yeah you can play around
  • 00:29:22 and get any color you want with that pot
  • 00:29:24 lid all right let's do pie chart snacks
  • 00:29:26 and just to start off I kind of
  • 00:29:30 mentioned this the histograms but to
  • 00:29:33 like figure out how to do a pie chart I
  • 00:29:34 usually just start at this documentation
  • 00:29:37 look up pie plot a pie chart is right
  • 00:29:41 there and then with this page I can kind
  • 00:29:46 of get all the details of what I can
  • 00:29:48 pass in and what are the parameters that
  • 00:29:51 I can play around with yeah a lot of
  • 00:29:57 good stuff here okay so the wedge sizes
  • 00:30:01 is our X and that's what we're gonna
  • 00:30:02 input here so what does that look like
  • 00:30:05 okay so I want to just output some of
  • 00:30:08 our data again and what I think we're
  • 00:30:12 gonna do for this first chart is one of
  • 00:30:15 the components of this I guess we can't
  • 00:30:19 see it here but if you opened up the
  • 00:30:21 full I can't see all of it if you opened
  • 00:30:26 up the full file within like Excel you'd
  • 00:30:29 see that one of the parameters we can
  • 00:30:31 have is preferred foot so if I look up
  • 00:30:38 that you see that left or right
  • 00:30:42 it's what whether you play left or ready
  • 00:30:44 in soccer so what I'm thinking would be
  • 00:30:47 interesting to do a pie chart on is the
  • 00:30:49 percentage of people that play with
  • 00:30:52 their left foot versus their right foot
  • 00:30:54 so how would we do something like that
  • 00:30:56 well we can count the number of people
  • 00:31:00 that play with our left foot by doing
  • 00:31:02 the following this plays into the stuff
  • 00:31:05 that I taught in the that we went
  • 00:31:07 through in the pandas video but we can
  • 00:31:11 use the dot lok to kind of like look up
  • 00:31:14 the data set and kind of filter the data
  • 00:31:17 set by specific condition in this case
  • 00:31:19 for left we want to the condition to be
  • 00:31:24 apologized one sec one the condition to
  • 00:31:27 be if the preferred foot column is equal
  • 00:31:34 to left then we want only the data that
  • 00:31:39 this condition holds and because we're
  • 00:31:41 going to need to pass this into a pie
  • 00:31:43 chart what we'll want to do is get the
  • 00:31:47 count of that I believe this count gives
  • 00:31:50 us an array I can probably check so
  • 00:31:54 let's see what is the left yeah it's
  • 00:31:57 like an array here so if we do count 0
  • 00:32:04 we'll actually get a number
  • 00:32:05 as you can see 4211 players prefer their
  • 00:32:10 left foot and so we can do the same
  • 00:32:14 thing with right FIFA
  • 00:32:16 FIFA bird foot equals equals right get
  • 00:32:26 the count of that and then because this
  • 00:32:28 returns a data frame we have to take the
  • 00:32:30 we'll just take the first element which
  • 00:32:32 it will be a number and let's see how
  • 00:32:35 much you like right okay so considerably
  • 00:32:37 more people preference their right foot
  • 00:32:39 than they left that makes sense okay so
  • 00:32:42 now how do I do the pie chart we can do
  • 00:32:44 plot pie this is from the documentation
  • 00:32:47 and I guess I kind of jumped ahead but
  • 00:32:50 you might like think maybe I can just go
  • 00:32:52 ahead and do FIFA preferred I can't even
  • 00:32:57 spell of course I like foot and like
  • 00:33:00 figure that it might just plot the pie
  • 00:33:02 chart well doing that but it it gets
  • 00:33:05 messed up when you don't pass it numbers
  • 00:33:09 so what we need to do is pass in a list
  • 00:33:12 of numbers so what we can do is left
  • 00:33:16 comma right so now we have two values
  • 00:33:21 and I'll make a part pie chart out of
  • 00:33:23 these values look at that cool and I'll
  • 00:33:27 do plot show one thing I'm noticing is
  • 00:33:31 these colors are really ugly and also
  • 00:33:33 nothing is labeled right now so going
  • 00:33:35 back to the documentation you can see
  • 00:33:41 labels is list sequence of strings
  • 00:33:45 providing the labels for each wedge we
  • 00:33:46 need to pass in that we can also change
  • 00:33:48 up the colors with an a writ list as
  • 00:33:50 well so let's do that so labels will do
  • 00:33:55 equals left and right and we'll pass
  • 00:34:04 those into our pie chart do labels
  • 00:34:08 equals labels cool so now at least we
  • 00:34:14 have like relative percentages I mean
  • 00:34:16 you don't know the exact percentages but
  • 00:34:19 you have an idea just based off the
  • 00:34:20 graph if we added in colors we could
  • 00:34:24 change this ugly
  • 00:34:25 from being there she could pass in two
  • 00:34:27 colors let's say like we're gonna just
  • 00:34:31 use some hexadecimal values I'm just
  • 00:34:33 typing in these in randomly and now I
  • 00:34:41 have two passing colors here cool now
  • 00:34:47 that looks alright maybe you'd want a
  • 00:34:48 little bit more contrast but it doesn't
  • 00:34:51 really matter too too much you can be
  • 00:34:53 the judge of that
  • 00:34:54 I do Auto percentage this should forget
  • 00:35:00 exactly how to format this I'll have to
  • 00:35:02 check so others percentage format
  • 00:35:10 percent so we can use percent notation
  • 00:35:17 here so we can do % point 2f and
  • 00:35:22 basically I'll just fill in whatever
  • 00:35:24 value is for the percentage with 0.2 two
  • 00:35:28 decimals of floats and I guess I screwed
  • 00:35:31 that up probably also be a string well
  • 00:35:38 so now it actually gives us our
  • 00:35:41 percentages so 23 point one nine percent
  • 00:35:43 of the people in the FIFA game prefer
  • 00:35:45 their left foot over their right foot
  • 00:35:46 and if you want to actually see percent
  • 00:35:49 on that it's a little bit weird and just
  • 00:35:51 do % percent basically if you just did
  • 00:35:54 percent I think good bug-out because
  • 00:35:56 it's expecting specific notation
  • 00:35:59 basically by doing two percentage points
  • 00:36:02 in this notation it knows you actually
  • 00:36:05 do want that percentage sign right and
  • 00:36:08 then we can add a label the title as
  • 00:36:10 we've done in the past preference
  • 00:36:16 foot preference of FIFA players cool and
  • 00:36:25 there's a basic pie chart I'm trying to
  • 00:36:27 think if there's other things I should
  • 00:36:28 add to this we'll get into a little bit
  • 00:36:33 more complicated stuff and the next pie
  • 00:36:36 chart that we'll build so this is a
  • 00:36:38 pretty simple
  • 00:36:38 pie chart let's make another pie chart
  • 00:36:40 all right pie chart number two so in
  • 00:36:43 this one what we're gonna do is look at
  • 00:36:46 the breakdown of the weights of the FIFA
  • 00:36:50 players and we'll plot it as a pie chart
  • 00:36:53 so I mean okay let's look at what the
  • 00:36:58 weights look like so I'm going to print
  • 00:37:00 out wait here okay so we have a list of
  • 00:37:05 all these weights we can see is that
  • 00:37:07 there and note that they're in pounds
  • 00:37:10 they're not into kilograms as many of
  • 00:37:13 you guys might expect and pounds but you
  • 00:37:16 could initial step you could do to this
  • 00:37:19 pie chart would be to convert all these
  • 00:37:20 values to kilograms that'd be a fun
  • 00:37:22 little exercise but okay we have all
  • 00:37:25 these pounds and one thing I immediately
  • 00:37:28 noticed is if we're trying to count
  • 00:37:30 ranges of these pounds it's gonna be
  • 00:37:32 tough with this pounds string attached
  • 00:37:35 is there anything else I notice here no
  • 00:37:39 it's mostly just that but okay so
  • 00:37:42 basically what I want to do is reset the
  • 00:37:45 weight category to not include these
  • 00:37:48 pounds and just be the number so this is
  • 00:37:52 going to be a string right now and we
  • 00:37:55 just want this converted to an integer
  • 00:37:56 so let's try to do that okay so we're
  • 00:38:02 going to reset the weight column and
  • 00:38:06 what we're gonna want to do is strip off
  • 00:38:09 so X here I'm going to do X for X in
  • 00:38:13 FIFA eight so X in this case is going to
  • 00:38:18 be a string so we can do strip lbs so
  • 00:38:23 that will give us just this part of the
  • 00:38:25 string perhaps in FIFA weight let's see
  • 00:38:28 if that works
  • 00:38:30 float object has no attribute strip
  • 00:38:32 interesting I'm expecting that all these
  • 00:38:38 would be strings start to start with but
  • 00:38:44 because they're not what we can add is
  • 00:38:46 an if statement within
  • 00:38:47 list comprehension I'm going to just say
  • 00:38:49 if type X equals equals strain I'm
  • 00:38:53 guessing maybe there's a couple of empty
  • 00:38:54 values or something so we're just gonna
  • 00:38:56 kind of ignore those and then else X so
  • 00:39:06 if type x equals equals string we're
  • 00:39:10 gonna do this else just leave it as is
  • 00:39:14 that's what we're saying here let's see
  • 00:39:17 if this works
  • 00:39:20 now we print out FIFA eight cool cool
  • 00:39:28 and I'm gonna take the first value real
  • 00:39:33 quick and notice it's still a string so
  • 00:39:36 we were gonna want to do to this line is
  • 00:39:39 surrounded with the int block which will
  • 00:39:41 convert it to an end and now if I look
  • 00:39:44 at this FIFA wait zero we get it as a
  • 00:39:51 integer value I don't know why it's
  • 00:39:53 giving a decimal here but should be an
  • 00:39:55 actual value and you notice because of
  • 00:39:57 the point zero we know that it probably
  • 00:39:59 is being read as a value okay so now we
  • 00:40:01 have these values set right so let's
  • 00:40:03 start counting things so we're going to
  • 00:40:05 start with light players and we'll say
  • 00:40:08 light players have a weight under this
  • 00:40:11 is kind of arbitrary my breasts say that
  • 00:40:12 they have a weight under 125 pounds and
  • 00:40:18 then we're going to count that just like
  • 00:40:21 we did in the last example then the next
  • 00:40:25 condition we'll do is I guess medium
  • 00:40:29 Lake players that would be above 125
  • 00:40:36 greater than equal to 125 then we need
  • 00:40:40 an Ann condition the end condition and
  • 00:40:42 the way we're going to format this with
  • 00:40:44 our pandas notation is like that and
  • 00:40:47 this is probably review a bit if you did
  • 00:40:51 watch watch through the pandas video
  • 00:40:53 that I did and FIFA 8 is
  • 00:40:57 less than 150 let's say so now we're
  • 00:41:02 getting only the rows that have both of
  • 00:41:05 these conditions true we're going to
  • 00:41:06 count that zero keep doing this I'll
  • 00:41:12 probably eat this up when I edit the
  • 00:41:15 video I'm going to just get three more
  • 00:41:18 categories all right cool so we have
  • 00:41:37 five different weight categories and I
  • 00:41:39 can like print these out
  • 00:41:40 I don't know invalid syntax what do they
  • 00:41:44 do
  • 00:41:44 Oh didn't end the 369 heavy people
  • 00:41:50 medium heavy let's see if this is a
  • 00:41:53 valid number four thousand so yeah it
  • 00:41:55 makes sense that there's more between
  • 00:41:57 170 and 200 then there are people over
  • 00:42:00 200 in a league it's kind of tough to be
  • 00:42:02 a soccer player over 200 pounds okay so
  • 00:42:06 let's now plot this so what we want to
  • 00:42:11 plot will be our weights and I'll make
  • 00:42:14 this an array light weight medium medium
  • 00:42:20 medium heavy and heavy our labels yeah
  • 00:42:32 can't type today
  • 00:42:34 all right so plot dot pie weights let's
  • 00:42:37 see what this looks like cool it looks
  • 00:42:41 pretty good but it has no labels right
  • 00:42:45 now and I'm gonna do a plot touch show
  • 00:42:48 so we need to add some labels so under
  • 00:42:56 125 it's the first one 125 to 150 is the
  • 00:43:02 second
  • 00:43:05 150 to 175 is the third and 175 to 200
  • 00:43:12 fourth and finally over 200 is the last
  • 00:43:17 and it will pass these in with our pipe
  • 00:43:20 chart okay cool so now we have all these
  • 00:43:26 labels one thing I don't like and this
  • 00:43:30 is a good little thing to know is you
  • 00:43:32 couldn't I don't like the default color
  • 00:43:34 scheme and instead of passing in all
  • 00:43:36 five of my own colors one thing you can
  • 00:43:38 actually do is I don't know what I just
  • 00:43:43 typed in I didn't mean to do that I'm
  • 00:43:45 getting ahead of myself is there's a
  • 00:43:47 plot style and so instead of the default
  • 00:43:51 which is currently set so as you can see
  • 00:43:54 it stays the same when I do that we're
  • 00:43:56 going to use the style of ggplot and
  • 00:43:59 I'll link a list of these different
  • 00:44:01 styles in the description so I
  • 00:44:04 personally like this color scheme a lot
  • 00:44:06 more when I change the style of our plot
  • 00:44:10 okay
  • 00:44:11 so that's pretty good we can also add
  • 00:44:13 the auto percentage as we did with the
  • 00:44:15 last example so percentage point 2f
  • 00:44:19 percent is just a percentage percentage
  • 00:44:22 but things are a little bit ugly in this
  • 00:44:26 case the things are squished together so
  • 00:44:29 how can we resolve this problem and
  • 00:44:31 really if you go into the documentation
  • 00:44:33 you'll see there's a lot of these weird
  • 00:44:36 names you might not know what everyone
  • 00:44:39 means but if you kind of look up like if
  • 00:44:42 you did a Google search like pie chart
  • 00:44:45 Python numbers getting in the way of
  • 00:44:48 each other you probably find some
  • 00:44:50 different solutions so one solution we
  • 00:44:51 could go ahead and try would be setting
  • 00:44:55 the percentage distance so the
  • 00:44:57 percentage distance is the percentage
  • 00:44:59 distance from the center of the graph so
  • 00:45:01 if I did centage equals percentage
  • 00:45:04 distance equals zero you'd see
  • 00:45:08 everything's right there so instead of
  • 00:45:10 that we'll do like zero point eight so
  • 00:45:12 this comes zero to one is within the
  • 00:45:15 chart and you could even do if you
  • 00:45:17 wanted to like 1.5 and that would be
  • 00:45:19 values outside the truck but 0.8 was a
  • 00:45:22 good value that I thought okay so this
  • 00:45:25 baby makes it a little bit better these
  • 00:45:27 numbers right here that I'm highlighting
  • 00:45:29 aren't as squished but they're still not
  • 00:45:31 great so the other thing we can actually
  • 00:45:33 do is use this explode property and what
  • 00:45:39 explode does it breaks the graph apart a
  • 00:45:42 bit and so let's see what that does so
  • 00:45:46 we need a list that's as big as our yeah
  • 00:45:52 this could be a list it can be too full
  • 00:45:53 I'm gonna say that those are two pool
  • 00:45:54 that's what I did when I was playing
  • 00:45:56 around with this
  • 00:45:57 it doesn't shouldn't matter yeah it's
  • 00:46:00 your point four I'm gonna these are the
  • 00:46:03 values I want to get to but we'll start
  • 00:46:04 with doing them all point one and I'll
  • 00:46:08 reason to why I got to the values that I
  • 00:46:10 got – okay so explode equals explode so
  • 00:46:14 this is gonna split the graph apart so
  • 00:46:16 it's not actually touching so you see
  • 00:46:19 that so that's cool but really we don't
  • 00:46:22 need everything exploded we really just
  • 00:46:24 need these values that are very close
  • 00:46:26 together to explode a bit so what we can
  • 00:46:29 do to that is all right so we want under
  • 00:46:32 125 and over 200 to be exploded a bit
  • 00:46:35 more as you can see those correspond to
  • 00:46:39 our labels here we don't really need 150
  • 00:46:43 to 175 to explode at all cuz that's
  • 00:46:45 pretty set we don't really need 175 to
  • 00:46:50 200 explode so what does this look like
  • 00:46:52 now and we'll have this explode a little
  • 00:46:55 bit this is this twelve point six one
  • 00:46:57 percent cool and I think that this looks
  • 00:47:02 decently good now you can more easily
  • 00:47:05 see the different slivers and I guess
  • 00:47:09 it's tough because this sliver is so
  • 00:47:10 small the under one under 125 but think
  • 00:47:13 that you can more easily read this then
  • 00:47:16 you could win all of them or compact
  • 00:47:18 together and as in the other examples we
  • 00:47:23 can also add a title so weight
  • 00:47:28 distribution
  • 00:47:30 of FIFA players and we would want to
  • 00:47:34 spay that this is in pounds cool and
  • 00:47:39 also as you notice because I changed the
  • 00:47:41 style the header actually changed too so
  • 00:47:44 that's one thing to be a little bit
  • 00:47:45 careful with with the styles but
  • 00:47:47 sometimes they can be very helpful all
  • 00:47:49 right because this video is getting kind
  • 00:47:51 of long we're going to end it with one
  • 00:47:52 more graph but if there's other types of
  • 00:47:55 graphs that I didn't cover in this video
  • 00:47:57 or my previous video that you want to
  • 00:47:59 see let me know in the comments so we're
  • 00:48:01 going to do a box and whiskers chart and
  • 00:48:03 really the question we're trying to ask
  • 00:48:05 here is how can we compare teams like
  • 00:48:09 the how good two different teams are in
  • 00:48:12 our set so looking back at our FIFA
  • 00:48:14 chart let's print that out so you can
  • 00:48:19 see that all these players have a club
  • 00:48:24 so we're trying to compare the relative
  • 00:48:26 strengths of different clubs and so
  • 00:48:29 there I thought that a good way to do
  • 00:48:33 that would be this to use this box and
  • 00:48:35 whiskers chart which shows shows your
  • 00:48:39 highest player or it shows your highest
  • 00:48:41 score if you have a box and whiskers
  • 00:48:43 chart it will show like the max it will
  • 00:48:47 show the mean and then I'll show a box
  • 00:48:49 around where the middle 50% of scores or
  • 00:48:52 values were I think that's a good way to
  • 00:48:54 compare a team where you can kind of see
  • 00:48:56 okay where's the best player at where's
  • 00:48:59 their worst player at if everyone got
  • 00:49:01 injured and then the the middle box is
  • 00:49:04 kind of like the core of the team like
  • 00:49:06 how good are they so I think it's a good
  • 00:49:09 way to potentially compare two different
  • 00:49:11 teams maybe you can disagree with me
  • 00:49:13 maybe there's a different way you would
  • 00:49:15 recommend but well that's what we're
  • 00:49:17 going to do in this example so to start
  • 00:49:20 let's take a couple teams and count
  • 00:49:24 their their overall scores for that Club
  • 00:49:30 so we'll start with I was a good team to
  • 00:49:33 start with go up top we'll start with FC
  • 00:49:37 Barcelona so we're gonna do Barcelona
  • 00:49:40 equals FIFA Lok so we're going to filter
  • 00:49:44 out all the rows that have people from
  • 00:49:47 Barcelona so we can do FIFA club equals
  • 00:49:51 equals FC Barcelona yeah cool and let's
  • 00:49:59 see and then we want when we do our
  • 00:50:02 averaging we're gonna want to take their
  • 00:50:05 overall score so we can just filter by
  • 00:50:09 that too so now if we print out
  • 00:50:13 Barcelona because we're comparing the
  • 00:50:16 overall scores I think that's the most
  • 00:50:18 useful metric you see we just have a
  • 00:50:20 list of all the players on Barcelona
  • 00:50:22 their relative their overall performance
  • 00:50:27 in FIFA cool then we could do that with
  • 00:50:31 another team let's say we do Real Madrid
  • 00:50:38 FIFA club equals equals Real Madrid and
  • 00:50:44 where you want to take their overall
  • 00:50:45 values as well cool so this is two
  • 00:50:50 different values we can see Madrid here
  • 00:50:52 and all those values okay so now let's
  • 00:50:55 plot a box and whiskers chart for that
  • 00:50:57 so to do that we do plot box plot we
  • 00:51:03 pass in Barcelona and it will pass in
  • 00:51:06 Madrid so these are the all the values
  • 00:51:10 for Barcelona and all the values for
  • 00:51:12 Madrid and corresponds to what we see
  • 00:51:14 here so it will know this function will
  • 00:51:17 know that it needs to make a box plot
  • 00:51:19 off of that so what does that look like
  • 00:51:27 okay one thing I noticed too this is
  • 00:51:32 also a residual effect of changing the
  • 00:51:34 style in one cell style is still changed
  • 00:51:37 I'm going to change the style of here
  • 00:51:40 back to our default style so default
  • 00:51:45 style looks like this graph doesn't
  • 00:51:47 really tell us too much right now but
  • 00:51:49 we'll get it to look a little better
  • 00:51:52 seconds and I want to do plot touch show
  • 00:51:56 so all this stuff is not there okay cool
  • 00:51:59 so this is a comparison of the two teams
  • 00:52:02 relatively you can see they're pretty
  • 00:52:03 dang even I'd say Barcelona has a slight
  • 00:52:07 advantage it seems like it's boxes a
  • 00:52:10 little bit higher than Real Madrid's but
  • 00:52:14 and also their best player is ranked
  • 00:52:17 better than really Madrid's best player
  • 00:52:19 but it's kind of annoying when it's just
  • 00:52:22 as one and two down here so let's add
  • 00:52:23 our labels so it's a list FC Barcelona
  • 00:52:33 and Real Madrid and then we can go into
  • 00:52:39 our box plot it has a labels property
  • 00:52:42 and you can double check the
  • 00:52:43 documentation to see this labels label
  • 00:52:45 is cool so now we have our two different
  • 00:52:50 box plots and so these two teams with
  • 00:52:54 this comparison I would just say that
  • 00:52:56 they look pretty similarly matched like
  • 00:52:58 they could go ahead to head probably be
  • 00:53:00 a pretty good game where you really see
  • 00:53:02 kind of the coolness of visualizing this
  • 00:53:06 data with a box and plot and like
  • 00:53:08 comparing two teams is when you take a
  • 00:53:10 team that's not as strong so my local
  • 00:53:13 team here in Boston is the New England
  • 00:53:16 Revolution they're an MLS soccer
  • 00:53:18 organization so I also pass in some
  • 00:53:22 scores for them and they're short tend
  • 00:53:27 names the revs so I just call them that
  • 00:53:29 instead of typing out the whole New
  • 00:53:31 England rival revolution every time and
  • 00:53:40 yeah I want to try say the England
  • 00:53:43 Revolution and we're going to take their
  • 00:53:49 overall and you could look at all the
  • 00:53:51 different teams in the data sheet and
  • 00:53:52 get like a certain team that you wanted
  • 00:53:54 to look at pretty easy yeah you just
  • 00:53:57 have to be careful that you type in
  • 00:53:58 everything properly and apparently I did
  • 00:54:01 something wrong oh okay
  • 00:54:06 we also have passing the ribs here cool
  • 00:54:09 so now we have three teams and you can
  • 00:54:13 see that the New England Revolution is
  • 00:54:15 significantly worse than Real Madrid or
  • 00:54:16 Barcelona which is what we were wanting
  • 00:54:19 to show let's add a title here and we'll
  • 00:54:23 add some style to this chart as well
  • 00:54:26 professional soccer team comparison and
  • 00:54:32 because I'm from the States I call it
  • 00:54:34 soccer yeah you probably call football
  • 00:54:36 but that is besides the point
  • 00:54:40 FIFA overall rating overall fitting is
  • 00:54:47 our y-axis and we have our teams down
  • 00:54:51 here in the x-axis that looks pretty
  • 00:54:53 good to me okay what we could also
  • 00:54:59 change up potentially would be our tick
  • 00:55:05 marks okay or we could change the figure
  • 00:55:10 size maybe it would look better if it
  • 00:55:12 stretched out a bit more along the
  • 00:55:14 y-axis so we'll change our figure size a
  • 00:55:16 bit plot dot figure fig size equals
  • 00:55:22 we'll have the Y dimension be greater
  • 00:55:24 than the X and as you can see now it
  • 00:55:27 looks like this and this gives us a
  • 00:55:29 little bit more detail in the actual
  • 00:55:31 scores among the two teams but you can
  • 00:55:34 still see the New England Revolution is
  • 00:55:36 not as good and also this name is kind
  • 00:55:40 of running into each other so I'm gonna
  • 00:55:42 shorten England Revolution – any
  • 00:55:45 revolution – it just kind of make it a
  • 00:55:48 little neater cool alright so the final
  • 00:55:50 thing we're gonna do is out a little bit
  • 00:55:51 of style to this graph so it looks a
  • 00:55:54 little bit better and you also if you
  • 00:55:56 wanted to yeah feel free to add more
  • 00:55:58 teams to this and like really see the
  • 00:56:01 differences between soccer teams and
  • 00:56:03 FIFA but we will add some color around
  • 00:56:07 the perimeters of these boxes maybe make
  • 00:56:09 this line a little thicker that
  • 00:56:10 represents this represents the median
  • 00:56:12 the arms
  • 00:56:14 okay so what I found him to be the best
  • 00:56:17 way to do this is I'm gonna save the
  • 00:56:20 boxes as the result of this plot and
  • 00:56:23 then basically what we can do is this
  • 00:56:25 will store the three different values
  • 00:56:28 we've plotted here so it will help us
  • 00:56:30 style each individual box a little
  • 00:56:32 easier so for blocks in boxes boxes so
  • 00:56:43 you're getting the box parameter from
  • 00:56:45 what was saved here we want to set the
  • 00:56:51 color and then this also kind of shows
  • 00:56:54 you that there's different ways to do
  • 00:56:56 these things like I could have passed
  • 00:56:57 color in here the problem with passing
  • 00:57:00 color within here is it would make
  • 00:57:02 everything the same color so if you
  • 00:57:04 wanted like go ahead and change a
  • 00:57:06 specific box I can have a list of colors
  • 00:57:12 it's easier or I guess maybe color is
  • 00:57:15 not the best example because colors
  • 00:57:17 probably would allow you to pass in an
  • 00:57:18 array but for certain properties it's
  • 00:57:21 hard to set just one value at a time so
  • 00:57:26 I'm going to go ahead and set the color
  • 00:57:27 here
  • 00:57:36 so now you see that we have a different
  • 00:57:38 color around our box and they're similar
  • 00:57:42 to boxes here there's another primer for
  • 00:57:45 like the longest strike here and the
  • 00:57:48 long strike here the whiskers of the box
  • 00:57:51 and whiskers plot but I think it could
  • 00:57:54 use to be a little thicker here and so
  • 00:57:59 to do that we're gonna do line width
  • 00:58:03 equals two and all these parameters I'm
  • 00:58:06 finding from the from the documentation
  • 00:58:13 okay cool so sit edge color basically
  • 00:58:19 and let's say we wanted to change the
  • 00:58:23 fill color so change fill color and you
  • 00:58:30 could as I said before like you could
  • 00:58:32 iterate through these and through a list
  • 00:58:35 and like each time set a different color
  • 00:58:38 for each of these change fill declare we
  • 00:58:40 can do something like set face color we
  • 00:58:43 could all do this in one line as well
  • 00:58:45 but kind of just showing different ways
  • 00:58:47 you can go about things face color is
  • 00:58:50 another property this actually changes
  • 00:58:52 the inside of the box so what happens
  • 00:58:54 going to do easier easier easy row this
  • 00:58:57 is a grayish color unknown property face
  • 00:59:00 color and this was something that I
  • 00:59:02 found super annoying when I was trying
  • 00:59:04 to do this so if you're trying to set
  • 00:59:08 the face color our box and whisker chart
  • 00:59:09 doesn't recognize I can't like recognize
  • 00:59:13 this property face color for whatever
  • 00:59:15 reason by default so you actually have
  • 00:59:17 to set this patch artists property to
  • 00:59:19 true to allow you to change the face
  • 00:59:22 color so now we have these graphs I
  • 00:59:24 think that looks a bit better we could
  • 00:59:28 also change up the median line so you
  • 00:59:31 could do it within this format or
  • 00:59:33 another way we can do it is one of the
  • 00:59:36 properties of box plot is median props
  • 00:59:40 so you can also pass in like a
  • 00:59:42 dictionary of median props and so we
  • 00:59:44 could pass in a line width here too so
  • 00:59:46 that's
  • 00:59:47 we wanted this line to have the same
  • 00:59:48 thickness as the outline pass that in
  • 00:59:54 and there we go a lot of the styling
  • 00:59:59 stuff it's really a matter of google
  • 01:00:03 searching really like you can look at
  • 01:00:05 the documentation find some things from
  • 01:00:06 the documentation what I find is
  • 01:00:08 sometimes quicker is to say how do I
  • 01:00:10 change the outline color in a box and
  • 01:00:13 whiskers chart Google search that find a
  • 01:00:16 Stack Overflow post and then like from
  • 01:00:18 there figure out I can do this type of
  • 01:00:20 technique that's what works usually well
  • 01:00:23 for me all right so yeah now we have
  • 01:00:27 these three teams being compared I'm
  • 01:00:30 going to strengthen graph a little bit
  • 01:00:31 so you can see better I think this is a
  • 01:00:33 kind of a cool way to visualize how
  • 01:00:34 teams compare in FIFA all right I'm
  • 01:00:38 gonna end the video here hopefully these
  • 01:00:40 graphs were helpful hopefully is helpful
  • 01:00:42 to combine the pandas unlike the CSV is
  • 01:00:45 with the matplotlib
  • 01:00:46 library if you found this video useful
  • 01:00:48 make sure to throw it a big thumbs up
  • 01:00:51 and also don't forget to subscribe
  • 01:00:52 because I'll be posting a lot of videos
  • 01:00:55 in the near future also feel free to
  • 01:00:58 leave a comment if I didn't explain
  • 01:01:00 something well enough or if you have a
  • 01:01:02 future video idea that I should work on
  • 01:01:04 let me know those things I'd be great
  • 01:01:06 but yeah that's all I got thank you for
  • 01:01:09 watching peace out
  • 01:01:11 I don't know I'm doing right now yeah
  • 01:01:15 peace
  • 01:01:17 [Music]
  • 01:01:24 you
  • 01:01:27 [Music]