WHT

Df.plot() | Python Plotting Tutorial W/ Matplotlib & Pandas (line Graph, Histogram, Pie Chart, Box & Whiskers)

Keith Galli

Subscribe Here

Likes

4,268

Views

141,552

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

Transcript:

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

0.3.0 | Wor Build 0.3.0 Installation Guide

Transcript: [MUSIC] Okay, so in this video? I want to take a look at the new windows on Raspberry Pi build 0.3.0 and this is the latest version. It's just been released today and this version you have to build by yourself. You have to get your own whim, and then you...

read more