Data Visualization with Python for Beginners | Max S | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Data Visualization with Python for Beginners

teacher avatar Max S, Power through programming

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

11 Lessons (1h 35m)
    • 1. Course Intro

      1:00
    • 2. Introduction to Matplotlib

      2:25
    • 3. Importing Libraries in Python

      8:40
    • 4. Dealing with Files in Python

      14:18
    • 5. Making Line and Scatter Plots

      14:07
    • 6. Adding Labels, Titles, Axis Ticks, and Changing Line Styles

      9:52
    • 7. Rotating Axis Ticks, Adding Text and Annotations

      7:57
    • 8. Adjusting Plot Sizes, Adding a Legend, and Saving the Plots

      8:33
    • 9. Creating 1-Dimensional and 2-Dimensional Histograms

      13:42
    • 10. Changing the Axis Scales

      13:27
    • 11. Course Outro

      0:40
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

341

Students

--

Projects

About This Class

Data and analytics are becoming increasingly important in our world and in modern day businesses. To start off with data analytics (and ultimately provide nice images of our results), we need to be able to plot our data, preferably in the way we imagine it in our heads.

Matplotlib provides many great plotting opportunities and methods for data visualization, and in this course we will be looking at some introductory methods for getting started with creating plots in Python.

Once we have a starting point for plotting data we can easily expand our knowledge to different areas to make sure we can best represent all of our data. 

Meet Your Teacher

Teacher Profile Image

Max S

Power through programming

Teacher

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Course Intro: Hey, everyone, it's Max. And welcome to my chorus data visualization with python for beginners. This course is made for beginner to intermediate level. So all that you require is some basic python programming experience. And in this course, you gonna learn how to visualize data using python. So you're gonna learn how to use map lot lib to visualize your data, you're gonna learn how to make things like scatter plots, line plots as well as how to create one dimensional and two dimensional hissed a grams. You're also gonna learn how to customize your grass by adding things like titles, legends, labels, text as well as how to annotate your graphs body. The end of this course, you're gonna be able to write python code to visualize your data. Using that problem, you're gonna be able to customize your visualizations toe. Clearly differentiate data in your graphs, and you're also gonna learn how to add clarity dear graphs, by adding things like labels, text and annotations 2. Introduction to Matplotlib: Hey, everyone and welcome. So in this tutorial, we're gonna be looking at plotting with Matt plot lib, and we're just gonna take a bunch of practical examples. And we're gonna look at how can we plot, for example, scatter plots or line plots, but also some more complicated things. Maybe, like hissed A grams. So these are all things that we're gonna be looking at? Um, we're gonna be using some real world examples to so that we actually get some practicality and they're not. That would just kind of generate some random numbers and plot those. So we actually want to be plotting real data may be reproduced. Some plots that we see online or something like that on DSO My pot live is just a really great library to do that within Python. Um, and you can see here I'm on the official website. So this is also where you can download it. You can, you know, see some descriptions to your some, maybe pictures or something, and get some sample plots, but you can go down. And if you see here is an actually installation guide. So if you go on here, um, this is pretty much pretty much tells you how to install it. You can get the, um you can use the apt get install. Or you can use Pip if you're on Mac os X. Um, where you could do something similar on windows. So also something that you're gonna need to use my pot lip is going to be, um, number time. So that's something that you're also gonna need to install. I'm gonna be using the anaconda or rather, the spider environment that's contained in the Anaconda platform from Continuum s O. That one looks like this on DSO. This is made from Canton human analytics and or rather from Continuum. And it's called an A condom, and it's just a really great platform. And we're gonna be using the spider environment here, and it just it contains all these packages already. So I'm another area, has numb. He already has my iPod lib. You know, SK learned all this stuff so you don't really need Teoh install it all. Maybe some stuff that we're gonna be using. Leader, it's just really great for numerical python and simulation, so you can go ahead and grab that too, and just use that and also has I python consoles and everything. But otherwise, you know, if you're using a different environment, that's no problem. You just gonna need to download these libraries. Um, yeah, you can find all the installation instructions here throughout the rest of the course. I'm just gonna assume that you've installed everything and that you've got it working. Um, you have It is just, you know, map out live. There's just so much great stuff that we could do with it. And the plotting features air just just incredible and still would just be, you know, really going through that in detail. Really seeing what Weaken dio, Um, and making sure that we use a lot of practical examples. 3. Importing Libraries in Python: everyone. And welcome this tutorial is gonna be a short review about importing libraries and python just so that we're all on the same page. So what exactly is a library? Well, the library is an external package that's created usually by 1/3 party or some other pricing developer, and it's made widely available for use eso. An example of where you can find a lot of libraries is get help. For example, on DSO. What's great about these libraries is that they're just kind of pre written sections of code, and we can actually import them. And then we have all of this pre Britain code available to us once we imported and weaken just pretty much access anything within this library and use it in our own coat. And this simplifies things a lot because you know, that means we don't have to rewrite a lot of the stuff like we don't have to rewrite how to find a square root every time you want to use that, or how to calculate a co sign. So that would be examples from the life math library or, you know, getting random numbers or doing plots or, you know, all this kind of stuff. So that's all pre written for us, and we can just use that. So let's look at some examples of how we can use stuff from libraries. So we're going to start off and our example is gonna be the math library. So to import a library, specifically the math library that's usually contained within Python, we're gonna do the following. We're going to write import, and then we're going to write the name of the library. So we're gonna write import math in this case. Now, you can see here in my profit environment, the import keyword actually gets highlighted, which means that it has a specific function. In this case, it imports the library that we have here on DSO. You have to make sure there are some standard libraries that come with pride than others you have to install. You can usually do that using pip, for example. Otherwise, they may be specific instruction guides, or there is a set up file that you can run if you download a library that sets it all up for you. Um, yeah, usually. Then once you have it installed, you can just do this import statement. Um, all right, so let's get started. And let's look at how we can use this math library. So now that we have math imported, we want to be able to use it, so we want to be able to access stuff from it. And one of the functions contained inside math is the square root function and its name inside math is actually s Q rt. So, yes. So that's how this function is called inside of this math library. And what it does is it allows us to use it to find the square root of the number that were in putting. So let's try to do that. And let's try toe just say that in a variable called X, um, and to use the squared function, we're going to go into the math library that we imported, and he we're gonna access sq rt. So the square root, Um, and now we can just put in any number here, and this will give us the square root of it. So it's putting in five, for example, um, and then actually see this. Let's just print out X. So if we run our code, we see here we have the square root of five. Now, how do I know that this square roots function name is sq rt Not square ruder. You know any other type of abbreviation? Well, usually for external libraries, there is a documentation that comes with it. And this documentation has it pretty much tells you all the functions contained inside, as well as how to use them, what the inputs are as well as the outputs that you get from them. And so, if you're not really sure what's contained inside the library or you're looking for a specific feature, you can always look at the documentation of the library. Usually, there's also some example code that comes with it. So if the documentation is a little bit confusing, can also just look at the example code. And that would just show you some worked examples on, you know, substandard things. So that's where I got this this square root. From now we can important math, but sometimes we have libraries that have really long names, and we want to just abbreviate them. So what we can do is instead of just importing math and having to write math dot every time we can do import math as M. And what this does is if I want to do something or if I want to use something in the math library. I don't actually type math like I did here. I just type em like this. And that's because math is imported with the short name em. And so now every time I do m dot that were first to the math library. So if I run this now, we see my code still works. But I have this kind of short abbreviation that I use here, which is really, really cool on that, you know, really helps, especially if these names get a lot a lot longer. So that's one way of importing another way of importing is using from. So here we have this import math as em. Now we're gonna common this out, and we're gonna look at the second way, which is going to be from and and then we have our library name here, and then we can do import. And so that's how this kind of looks like. So we have from And then here we have the kind of put this maybe in Asterix or something. Library name, and then we import. And then here we can put in the features that we want to import. So this is kind of the Syntex for that. So an example for the math library would be from math imports. Um, ask you r T. And so what this does is this imports the square root function directly into our code and actually don't have to type m dot at all anymore. It's just directly available for my use. So I can also run it like this? No. And even if I would write math thought, for example, um, well, my python environment actually saved what happened before. But usually, if you just go ahead and write this like this, you're going to get an error. So once you import from something and you import it, then you usually just refer to it like this rather than having the extension in front of it so that you can just directly access it in your code. Um, So what are the pros and cons of this? Well, the pros, for example, is that we're only importing a small part, so we're not actually importing the whole library. If we don't need it because that may take up a lot of memory space on DSO. This is kind of a way to preserve memory, for example, so if I import only the square root function rather than the whole math library, I only have one function that I can call. But that's also the don't downside. So if you remember or what we can see, actually, if we kind of put this back in, and if we do m dot then here we have a bunch of suggestions about, you know, the features and the functions contained inside of the math library. And so if we look at the coastline one for example, and if I take us away and I comment this out again and I just have my from math import square root, then I can't actually access the co sign because the coastline isn't defined because I only imported the square root so I can only use the square root because that's what I imported. But I can't use anything else. So if I want to import the screwed and the coastline I could separated by commas like this and a foul someone imports Simon, I can also do another comment like this so I can import specific functions if I want. And then I could put the coast on here, for example. Now, now I get the coast on. But these are things that we're also gonna have to watch out for. One more thing that we can do, rather than having thes individual names here. What we can do is we can do from math import star and what this does is it imports the whole month library. But now we're not referring to it with math thought anymore. Now we can just directly refer to it by there by the name of the of the function. So, like, we can directly right co sign we're sign or hyperbolic sign without having to write math thought in front. And so these are the kind of two ways of importing that we can go about. Um, they both have their advantages and disadvantages. I would usually not recommend importing everything for meth. Um, if you want to do this, you should probably do this just because it's a nicer to read and you could have some conflicting code later on. But this is really nice. If you only need specific features that you want to use 4. Dealing with Files in Python: everyone on DSO In this tutorial, we're gonna look a little bit of a recap at how we can open files and pipe them. Now, what we're gonna do is we're gonna first create a file, Um, and then we're gonna read the file back. So that's how we're gonna go on. We're gonna maybe remember or see some of the things of of how we can open files and how this whole process kind of works. So to go ahead, we're just gonna start Andi the one of the standard way. So there are two ways that we can actually do it. I'll show you the standard way first, and then I'll show you the one that I actually prefer. So we'll just call or will it just rather save our file in the variable will call it F. And the file is or F is gonna be. And now to actually open a file, we have to write open So the open keyword, and then we can just give our final name. So my file dot txt, for example. So that's gonna be our file name, and then the second argument is gonna be what we want to do. So right now, we're gonna want to write to our file love like this. So we're gonna have f is open my txt, and we're gonna want to write to it. Now. What this right does is that well, if we have the file, it opens it. But if we don't have the file created yet, it actually creates the file for us in this location. So the file is created in the same kind of location that your code is in em. So be in the same directory for the same folder. I mean, so that's what this right does. And that's not the same for reading in a Pending, but for writing, at least the file gets created for you if it's not there yet. So now that we have our file, we can actually write something Teoh So we can do f dot Right? For example, Um, and let's just right hello to it. Like this. Um And so now we've opened my file dot txt that we've opened in writing mode. We've written hello to it, and now we can just close our file and that just makes sure that all the memory and stuff is taken care of on and that there are no errors or the files and corrupted or any of that stuff. So this is kind of the basic syntax that we have. This variable would restore our file in. Um, we have this open keyword. We have our file name here, and then we have what we want to do. In this case, you want to write to it, and then we just write hello to it and then we close our file again. So that's it for this This file. So now my fault out. Txt contains. Hello. Now what we can do is we can actually open the file again. Maybe So let's say I'm and I can reuse f not because I closed the file so I won't have any kind of errors of stuff coming from here. Since I closed the file, I can reuse f and I can say now I want to open Um, my file, doc txt and not what I want to do is I want to append to it, which is the A. And so what that does is it looks me right to the end of this file. So if I open it in writing mode. When I start writing, it's actually gonna overwrite my file. Whereas if I open it in the pending mode like this, it's actually gonna add to the end of my file. So now what I can do is I can write or I could go into F and I can write, um, world like this. So now I have hello worlds in my file called my file dot Txt. And now I'm gonna close it again so f dot clothes like this. All right, so now we want to go ahead and read our file. You can always. Of course, while we're doing any of this and as soon as you're on your coat, you can go ahead and look at your folder and stuff and just look at the text file. But we'll just do this all in here. So now we're gonna use deaf, and now we're gonna open my filed out txt, and we're gonna open it in reading mode like this. And now what we're gonna do is we're gonna say f dot breed line, which reads the first line of F and then or let's save it in line so line is going to contain the first line of F. Um, and what we can do is we can print line. All right, So what happens when we read a line or what happens when we read from the file is we have a kind of pointer pointing to a partner file. So let's say our file right now it looks like this Hello world. And right now, our pointers kind of here. It's at the very beginning, Um, and not when it reads the line or when we call this our pointer kind of says, OK, I've read all of this. Um And so now Well, all right, now I'm going to be on the next line. So if I call read line again. And if I had a second line, I would actually were none. Then read the second line, and so your point or kind of moves with it, And that kind of gives the location that you are in your point in your file now you can, of course, change that. You can kind of repossessed in the counter if you want, but we're not going to really look into it that much because we don't I really need that right now. We're just gonna look at how it can kind of the basics of reading from files and also understand why we can always use this read line and every time, get the next line. All right, so let's just run her coat on and let's see what we got. So like, like I wrote up here we get Hello, world. Um, we noticed that there is no spaces. There is really no formatting onda reason that is is, you know, rather than for the print statement, we actually have a new line underneath. If we write to a file, nothing else is added to it. So we don't get any extra spaces. We don't get a new line and stuff s so we have to add that all manually. So, for example, if I wanna have a space between Helen Rolled, I'm going to right here, f dot Right. And then I actually have to manually put into space. Now, it's also important to note that you can only write strings to files. So let's say Well, first off on this and we see I've got the space here. Now, if I try to write a number like this, I'm gonna get an error. And that's because the argument of right must be a strength. I can't put anything else in here. So if I cast this to a string, for example, like this, so using this str this converts one to a string. So if you're not familiar with this with str one does is it turns one into one like this himself. I run my coat. Now we see we've got the one here. This would be the same as just writing one like this. So either of these would would do either of these kind of left me right numbers in there, but yeah, let's just leave that for now. That's just kind of effect. Um, all right, so this is how we can do the space is now something else that we're not really getting in. Here is new lines, so we only have one line right now. And to add a new line, we actually have to f dot right? I'm a new line, which to write a new line is the backslash and character. So backslash kind of escapes our quotation marks in some sense and says that the next character is special on DSO. What backslash end does is it writes a new line. So if you run our code now we see that we've also got the kind of new line that's appearing here. So that's what the F dot reid line does. Um, OK, so that's it for reading files. Maybe one more quick thing that we should look at, how we can kind of deal with the data that we get from the files. So right now we have hello world, just kind of as one strength and maybe you want to split that into a list. So what we can do is we can say, Well, if we print line now, what we can do, first of all, is we can strip off the trailing new line. So what that does is it just takes away this new line at the very end. So if we run our code now, we see we've got hello world here. Um, but then we don't really see that big of a difference, but the new line is actually stripped away from this one. So if I change this up and if I print but print the line again afterwards, We'll see. There's actually knew known new line after this one, and the only new line that comes from is this print statement. So that's why we have things on a different line. But here we actually see we have one new line which comes from the new line. That's part of the file. And we have one new language comes from the print statement. So what this stripped statement does is it takes away this new line at the very end. So now we just have the string Hello, world without the new line, The very end. So now what we can do also is weaken prints, um, line and those. So now we stripped away the new line. And if you want this in a list, we can split it. And so what this does is, and now we have to put in a special kind of circumstance that we want to split by. So let's split by a space now. What this does is it goes through this string here, and every time we have a space, it kind of makes that a element of a list. So it starts here, and it goes and goes and goes, and then it sees a space and that tells the programme or that means I'm OK. So everything up to this space is the first element. And now it continues on and then it reaches the end. And so now we only have two elements because we only have one space here. So if we run this we see now we have a string containing hello as the first element and world as the second element. So if he right for example, 1/3 element so f top, right, Andi, Now, if we can actually just at the space in here to hello world and then we can write maybe again. So if we run our coat now, we have this extra space here. So instead of adding the space manually afterwards, we just put the space in here. If you run it now we see we have hello world again. And now we saw that everything up to this space is the first element. Then after the spaces thesis element, until we reached this space and then everything after that is the third element. And so that's how we can split. Or that's how we can kind of parse our data that we have in a string and we can put that into a list. Now, if we have integers, we have to convert those to introduce. So we're not really dealing with interviews right now, but the way that we could convert those two interests would be a similar or thing that we did up here. So the string of the integer one, for example converts it to the number one. But we can also do is we can do Prince. And I mean, this isn't really gonna make a difference where we won't see it on the output. But it's the principle. If we printed the introversion of the string one this into cast So what? This does int of the string one. This turns the string or the word one to the integer one if possible. Um, so this only works. Of course, if this is a number in here, if this is one like this, for example, this is gonna be an error. Um, but if it's ah integer like this, then it's going to work. So we won't We can't really tell the difference between the integer and the string here, but this is the principle. So what we can do, for example, is we can go through our list and we can say each or weaken. Rather, we can replace each string version, Um, of the element that we got, because when we read a line, we get only strings. We can replace that with the interviewer version of it. Okay, so that was the one version of dealing with files. And now after this, we have to make sure we close f dot close. So we close our file again. M so that now that we're done with this reading of the file, we close f no. So this is the kind of standard way of dealing with files. We have this open and close statement. Now, another way that we can deal with files is using a with statement so we can say with and then we can write open. And we just do well, just with a set, we'll just do the same thing of opening the file for reading. So we'll say with open my file dot txt, um, in reading mode. And they were going to say with open this as f um then we can do the following. And so what this does is this is pretty much the same as this. This saves the my file dot txt in reading mode in this F variable, and we can do the same thing here and do f dot read line, for example, and say, uh, let's say it line to just so that just to show that it's actually different. And if we print line two here, um, so if you run or code we see here we have the hello world again. That's that comes from this statement here. But what's really great about this is that after this, So once we're out of the indentation here, we don't have to worry about closing the file or stuff anymore. So that's all taken care of in this statement here on, But I prefer to use this one just because, you know, you don't have to close the file and it's a little bit cleaner way of opening on dealing with everything, but you can pretty much use whichever one you like. Um, but this is the one that I'm gonna be using. So this is just do kind of show you the syntax of it and everything that's within this indentation. I can use f to access the file. And once I'm outside of this indentation, I actually can't call f anymore. So once I'm outside of this indentation here and I'm back here, for example, and I tried to print F'd up read line. Um, it's going to give me an error because, um, f is closed once, once I'm outside of this indentation, so I can't access it anymore. And so this kind of is taking care of automatically for us, which is which is really nice, but yeah, this is just to kind of show you that this version here and this version here there they're pretty much identical in most cases, so we can do the same things. This is just kind of a different way of writing it 5. Making Line and Scatter Plots: everyone. And welcome to my editorial imploding with map lot lib. Now, Matt Platelet is a great library to use in python for a bunch of plotting. I'm pretty much lets us use all the Matlack plotting functions or features directly in Python. So, yeah, let's just get started And let's just see what we get. We're going to start off with making line and scatter plots. So to get Matt plot lip, we're gonna go ahead and important, Matt, plot lib, and specifically, we're gonna implore port hi, plot like this and we're gonna imported as plt because this is just a long name. So we want to have a short form for it. And so in this pipe lot we have, you know, all the kind of typical two D plotting features will go ahead and use some other features containing map plot the later too. But let's just start with the pipeline basics right now. Um, now, the data that we're gonna be plotting is gonna be the Bundesliga 16 4017 season. Um, and we're just gonna look at the goals. We're gonna look at the each individual match, and the goal is scored there. So we're gonna look at the home team goals as well as the away team goals. Um and so that's the data that we're going to putting out. I could put a link to the websites in the description below where you can actually find, um, all the CSE files. But I've actually kind of just taken this data out of the CSE files and written it into a separate text file just so that it's easier to deal with and that we don't actually have to deal with a lot of importing the day, their data rather that we can just kind of get it out of the text file. Eso the first line would be the home team. Goals scored each match, and the second line would be the corresponding away tingles. So that just kind of makes it easier to handle data. So let's just go ahead and import this data. Um and so what we're gonna do with we're just gonna go with open and now the files called goals dot txt and we want to open this for reading. And we were just gonna open it as f um and so we're gonna take our home team goals and we'll store it in the variable called home Tingles. And what we're gonna do is we're going to go into F and we're going to read the first line . Then we're going to strip away the final back such and character. So the new line at the very end and all the way this data structured is that each line ends with a space and a back slash m. So each line lands with a space and a new line character. So we also have to strip away the finalists space. Um, and now we can just split all the data, um, by each space. So we have a number and a space in the new number. And so that's what we're just gonna kind of split everything by spaces. And so this is going to give us a list of strings. Um, for each strength pretty much corresponds to the home team goal of each game. So each element is one game. And in this home team goals list, we have the, uh, the goal that the home team scored for that game. And so since we're gonna be plotting, we want to turn this into integers. So we're just gonna use this nice little feature where we can put square brackets around this and we can go and type into X for X in and this expression. So what this does is it goes S o X goes through this list that we've created here, which is the string version of each of the goals that that have been scored each game. And it just pretty much says it as the inter diversion and this all gets saved as a list in here. I'm inside the home team Goals variable. Um, yeah, Cool. So now we can do the same thing for the away team goals and we'll just start off with the same thing. Well, let's just start off with this statement here. So now that we've read the first line, we want to read the second line of F and here again, we have to take away the new line character at the very end as well as the extra space. And then we're going to split it by the space eso. Now we've got a list of strings again, corresponding to the away team. Goals scored for each game and then we wanna make sure this these are all integers. So we cast it to the interviewer version of X, and we go through this list that we've created here element by element. Cool. So this is kind of the simple way of just important today. Also, this is just specially formatted for this on. You can also find out down below. Um okay, cool. But yeah, So without any further ado, let's move on and directly plot this data. So the way that we can plot is we're just gonna go ahead and to say plt on. And so we're gonna go into map loud, lived up. I plot and we're just going to directly access clock like this. And now what we condemn her, for example, is Theo X and the Y variable. But we can also just enter a why variable directly, for example, the home team goals. And if we don't specify an X variable, one will be created for us, and it's gonna be kind of a standard X. Very well, that's gonna be created using the range function. So if we should, if we kind of see this graph, so to see this graph. We first have to say what we want to plot, and then finally, to see it, we have to go into plt dot show. So this actually wants to see the graph at the very end. One. So now if we run this, we see is this is the graph that has appeared on BC That X variables have kind of been created for us because we didn't specify any soap. There's only one very one put it just assumes that these air all why variables on DSO That's what we kind of see on this. Why access to you that corresponds to the home team goals and each of these X variables is just an integer ranging from zero up to what looks like about 1 45 We can also create our custom X variables by going, for example, um, let's just say X variable is an empty list, and then we say for I in the range, and so we create a range and the range is gonna be from zero up to the length of the home. Only team goals like this and what we're gonna do is we're just gonna take our X variable and to it. We're going to append I and so this is pretty much gonna give us the exact same numbers that we got here. But now we can also put them in here and have an X variable like this and as well, we can also have a y variable. So if we run this now we see we we got the same plot that we got above. But now we have an X as well as a wide Very now we can also, for example, plot the away team goals. And so this plot would look a little bit different. Um, like this. So, for example, we see an immediate difference that six is the maximum number of home team go scored and five, the maximum number of away team goals scored. Um, but what's also kind of annoying, I guess, is that there's an extra white space here, and so maybe we should try to minimize that a little bit so we can change the limits on day . We're just gonna start off changing the excellent first. So we're going toe plt and to change the excellent we're gonna look at the X limb feature and the lower limit will keep a zero. And the upper limit will put two, maybe 1 45 like this. So let's go ahead and run that nice. Okay, this So this is we've gotten rid of those wide spaces. This looks a little bit better. Maybe we can also change the why limit eso that we have kind of an extra space here s so we could go into plt and similarly, just changed the y limit and go from zero up to six, just to make sure that five really is the maximum value. Um, And so if you run this here, we see that, um, you know, well, five is a maximum value, but this is Scott is also a little bit better to look at because it's not being cut off directly at the top. So this this looks a little bit nicer. Now, something else that we can do is we can also change the color so we can say seeing is equal to bread, for example. Um and this lets us change the color. So if we see now, um, marker office become, read, do the same thing, we could change the green. For example, and now our line is gonna become green and so on. So this is another one of those things that we can do to kind of distinguish, um, multiple graphs. So what do I mean, distinguish multiple grass? Well, what if we put in another line here? So what if for one you know will pop the away team goals, but let's in the same graph. Also plot the home tingles so we can go into plt again and we can go into plot. And then we'll just put the x variable again as the x variable aan den. We're gonna plot the home team goals, and here we're going to say the color is going to be Look, so now we're creating two plots. One plot is the X variable versus the way team goals, and the 2nd 1 is the X variable is versus the home tingles. So the X variable is gonna be on the X axis. Um And so if we run this now, now we see we've got the blue line which corresponds to the home team goals as well as the green line which corresponds to the away team goals so we can actually overlay these thoughts with a different kind of futurist or a different kind of plots and just kind of put them together, which is also very nice. Yeah, So we can also just directly through this kind of compare similar graphs or something like that, or look at differences or look at individual segments, you know, see where they differ. For example, Here we see you know, the this this five big here, for example, seems to correspond to a lower kind of home team goal and stuff like that. So we can kind of see that from the graph, maybe not directly, but also gives us a little bit nicer of an overview. And so this is also what happens when you call plot. Until you go into show, you're going to refer to the same figure unless you explicitly say that you're referring to a different figure or a different subplot. But we'll get into that later. So right now, what we can see is that if we call the plot function twice without calling showing between , we're gonna see that we're referring to the same kind of figure for the same plot. Now what we can do for example, is if we go into here and do plt dot show and if we run this now, they're gonna be on separate blocks. So we've shown the first plant. So we've created the first pot and then we show it. And now we create a new plot that isn't, you know, this isn't really part of it anymore. And then we showed that you can also see that the excrement and the UAE limit no longer apply to the first plot because it's been shown on DSO once it's been shown, we don't really refer to it anymore. So once it created this new plot, um, everything after this is gonna be in reference to this new plot that we've that we're referring to now so we can see the X element in the why limit have been adjusted. Well, not really, because the Y limit is still six just from the nature of this plant, but they have technically been adjusted, whereas they haven't been adjusted here. So this is kind of how we can do line plots. Um, now, maybe we want also do a scatter plot instead. So let's just common doubt this plt don't show for now. And instead of plotting connected lines, we can also just pop plot the individual points by doing scatter like this. And so if we plot it now, we're gonna have to scatter plots and they're gonna be in the same plot again because we're not showing it. So they're gonna be in the same plot, and they're just now scattered points rather than connected connected points. And so that's what the scattered us. Now, these circles actually seem quite big, so we can reduce the size where we can manually set the size. So let's say S is equal to five. And this sets the size of these circles. We could do the same thing here. And if we run it again now we see that the circles have gotten a lot smaller. We can also make him a lot bigger by making it, for example, 50. But that's not really gonna help us much, because then they're just going to kind of overfill each other, and we can't really distinguish them anymore. So it's always nice to make sure that your everything is kind of distinguishable. Um, maybe one more thing that we want to do is change the y lower limit because we can't really see We can only see half the circles here. So instead of having it, the zero let's have it be negative 0.5 negative 0.5 like this. And so if we run it now and we see we've given a little bit of extra questioning space down here, we've got this nice scatter plot going on. It's kind of hard to distinguish the colors here, So maybe we'll just set the size maybe 28 or something. And just to really make a distinguishable will also change blue to red. Um, it's a little bit better still not that good. So I mean, you can play around with a size a little bit so we can set the size to 12 for example on. And then we get something like this. So here you can kind of start distinguish if you have good eyes. Um, if not, you can always make it bigger again. But yeah, So this is kind of how the plotting looks like the basics of plotting. We can get a lot more complicated and we will get a lot more complicated. We can do a lot more features. Um, this is really just kind of the basics that we're looking at and we can see here that we can kind of overlay different plots onto the same figure onto the same subplot. As long as we don't show it on, dunce. We show in between here, then we're gonna be creating different plots. So everything above here above this show corresponds to the plot that's gonna be shown here . And then after that, we're gonna create a completely new plot that's gonna have different features. Yeah. Cool. Alright, guys. So this has been the first tutorial for the map cloud lip and for plotting my part. Look, yeah, look forward to seeing you guys in the 2nd 1 6. Adding Labels, Titles, Axis Ticks, and Changing Line Styles: everyone. And welcome back to the second tutorial on plotting with Matt Claude Lib. Um, in this tutorial, we're gonna look at labels, titles, adding ticks. So adding kind of X X is and why access ticks in and changing those so that we can maybe put in game numbers or dates or stuff like that rather than just having numbers. And I'm also gonna look at the line styles of plots a little bit. So, like, how can we dog dash lines, for example, or dotted lines? All right, So yeah, let's just go ahead and jump in and and the first thing that we want Lookout is maybe adding titles. Um, so to do, to add a title, we can go into plt and we can type in title like this, and then we'll just put in the title here, and the title is gonna be our first club like this. Um, and now we see here that this this show is being called. So if we run this, where we're going to get is our first plot is gonna have a title. The second plot isn't going to, um, so Yeah, but this is kind of we've created a title here. Here. We could do the same thing down here and go appeal t dot title and we can call us are second plot. And now if we run this, we see that's now. Our second thought also has a title. So everything after the show corresponds to a new plot. Um and so we've created kind of do different titles. But for now, let's just take these out and let's just work with one general plot. So again, if you run this now, we see we've got one plot with one title, all right, so let's also adds, and maybe an X and a y axis label. So we'll call her Plt, dots X label, um, and will level or ex access to be just game number like this. And then we can go into plt dot Why label and we can label or why access to be goals scored . So if we run this now, we see we've got the title or for a spot down here we see game number, which is Theo xxx label. Here we see the why label, which is goals scored. So this is just kind of adding general text We can also add logic text, for example, So equations eso the way that we can do that. Let's just out of that into the title. But we can really do that anywhere. Is that we put in our in front of our quotation marks. And so we can do here now is we can add logic like equations. So we can, for example, creates a fraction and say one half. And if we run this now, Oh, well, we have to enter math mood. So there we go. If you're familiar with logic, um then if we we type this, we see that we get this 1/2. So what this with these symbols mean here is that we're entering the math mode, Um, and that allows us to actually type in these thes fraction type of things, for example, that we see here. And so the way that we can do that is that we actually have to act at this, are right in front of our quotation marks, and that lets us at all these special features of logic. So if you're familiar with logic and you want to add a special type of labelling or a special type of text and stuff. You can do that. Just, you know, put this are in frontier. You can add fractions, you know, But you can just pretty much just generally add everything that you have in standard logic . Um, so we can do that, too. We can really customize our text and make it really nice and, you know, intricate on and everything and was really, you know, the way we wanted that we don't need toe kind of edit the titles and stuff later. Or have you know, these these weird underscores. Yeah. We can just kind of use the law tech features that are contained in my plot love, um, and make the labels and text generally very, very nice. All right, so this is these are the kind of ex labels and titles, and we can obviously do the same thing here just by adding our and then we can, you know, add some other other other things in here, so you can have, for example, affection of 1/3 or something. You can just generally add whatever you like. It doesn't have to be fractions, of course, at anything more useful that you'd like we can also adds, let's say, um, an underscore, you know? So if we take this back and we go underscore five, for example, and if we run this, then we see down here, we've got this the slower place five. So it's kind of hard to see right now, but we do have a lower case five down here. So, like a subscript, not a lower case. A subscript. Yeah, so you can just add a bunch of stuff. Just remember to put this our symbol in front of when you start your quotation marks. All right? Um, yeah. So let's look at changing these ticks. So instead of having 0 2040 60 80 bubble, whatever, let's give these custom tips or ticks. So the way that we can do that is we can kind of let's just create a list that has our ticks. So our ticks are going to be equal to, um and let's just say Game one. We're gonna be our first tick. Then we'll have Game 50 as their second tick and author ticket's gonna be game. Let's just say, Well, we'll call a game 100 global putting numbers here now. Um, All right. So we want to add these special tick labels down here, and we want to make sure they fit directly where they should. So we're gonna do is we're gonna go to appeal t and then look at the X ticks. And now we need to put in here what we want to replace and what we want to replace it by. So what we want to replace is we'll put that in a second and what we want to replace it. Bias the ticks. And so the first game actually corresponds to element zero just because of the way that counting kind of works in programming. So we want toe replace zero with game one, Game 50 is going to be 49 Game 100 is gonna be 99. And so if we run this, we see that all the kind of extra ticks have been taken away and they've been replaced with their custom ticks. We can also see here that rather here we have ticks every 20 here Now we have takes about every 50 ish. Andi was nothing before or after that. So we can do for examples. We can actually just go into here and say, Well, we want to replace 49 for example, with, and we have to make sure that we actually put a list here not just seeing elements with 40 nine like this. Um, and so that gives us one kind of tick over here with 49 replaced by 49. Um, yeah, we could do the same thing for the y axis, so plt dot Why ticks? And then we can change the element three, for example, to be three goals like this. And so if you're on this now, we see we've got the 49 down here and the three goals over here, Um and so this is kind of just taking care of those ticks Will look at rotating them a little bit later. But first, we want to look at one more thing, which is going to be the line styles. Um, So what do I mean by that? Well, if we go back into plotting is kind of standard lines like we did before. So rather than having appeal, we've got to take this s away. So s isn't defined for plaudits, only to fund for scatter. So if you run this Now we see we've got kind of these three standard lines that we have before, and we have the corresponding colors and stuff that would change. But what if you want tohave dashed lines, for example? So are we want our green lines to be dashed rather than home We can do is we could go into Ellis, which is, um, lifestyle, and then we can make this equal to and then if you type in a double dash, that actually corresponds to a dash line. So if we run this, we see we've got a dashed line here. We want a red line to be dotted. Weaken, go into Ellis, for example. And here we can go put in a colon which corresponds to a dotted line. So here we see, we've got a dash lime, which is green, and a dotted line which is red. So you can also really customize our lifestyles and everything. Um, they're off course other things that you can put here so you can look at the documentation if you're looking for some specific type of styles or if you will have, you know, in four or five plots in the same graph. And you want to change those styles, then, of course, you can kind of look at that to, um, you know, maybe you wanna have dashed and dotted. And what else is there, Dash daughter. You know, whatever else that you want to have, you can kind of look those up and for specific styles and then incorporate those however you like. All right? Yeah. So this pretty much sums up the basics of looking at labels, titles, ticks as well as line styles. Um, we also saw how weaken abs, you know, logic equations, stipe stuff to our all over text. Um, yeah. Great. So I hope you guys enjoyed this tutorial, and I will see you in the next tutorial then. 7. Rotating Axis Ticks, Adding Text and Annotations: everyone. Welcome back to the third tutorial on plotting with Matt Plod Lab. We're gonna look at today's we're gonna look at rotating ticks as well as adding text and annotating our plots. So if you just go ahead and plot what we had last time, we see that we still got our dashed in our dotted lines from before. We've got our special ticks that we've created here, um, friend or labels and our title. So maybe the first thing that we want to do is you want to change the rotation of this three goals and we wanna rotated by 90 degrees so that it's kind of vertical rather than horizontal. So the way that we can do that is we can go into our why ticks, which is what we want to change. And we can set the rotation to be equal to 90 degrees. And so if you run this now we see that we've rotated Arctic by nine degrees. We can do the same thing on the X six year and said our rotation to be equal to 45. I mean, he now we've got the kind of diagonal tick for this. So this is nice. For example, if you're adding dates, so if we just add a kind of a random date here, let's say 12 12 12 or something like the US And if we run this, then we see we get kind of this. This rotation here kind of add something nice to the to the date. So if we have a bunch of, you know, ticks next, each other, this is a little bit easier way of reading. Everything okay? Great. Um, so let's just go ahead and move onto the next thing immediately, which is gonna be adding text. So the way that we can do that is we can go into plt m. And here we want to look at text, and now we're gonna put in the X and Y coordinates of the checks that we want ad. So the X coordinate is going to be, let's say 50 and this corresponds to the coordinates on your graph. So Xcor was gonna be 50. She's gonna be actually right here and and then r y coordinate, let's have a before, And the text that we're gonna add is just gonna be our custom text like this and so if you run this now, we see our text starts over here right at 50. And then at four. So that's about right here. And then we just kind of have this custom text in here. We can change the font size. Um, maybe you happen to be a little bit smaller, Let's say 10 or something. Eso that We're not really going too much over Intergraph, okay? Didn't really change much. So let's have you do it. Eight. So our phones have become a little bit smaller. We can also change the color, for example, and have this one be Let's have this color, baby Blue. All right, So color in this case has to be written color like that instead of the sea that we have for the plot up here. So we've got our kind of custom text which is blue in color, font, size, age. We can also add this, you know, special logic style, and we can add, you know, whatever you want, here are two power three or something like that just to kind of show you what can be done. So we've got this kind of to the power three over here that we can add through our special lotto type code to our text so we can do all of this just like before. Eso This is adding special text. Now, if we want to do special types of annotation now, there is a lot, a lot that you can do on annotation, and we'll probably have a separate video on this later to get really into depth. But just to kind of look at the details and specifically just to know that it's possible that you can do this type of stuff and then if you're really interested, you can just go ahead. You know, whenever you need to just really dig into it, there's always get to know this type of stuff is possible. So to annotate, we're gonna go and go into plt dot You're not it like this. And then we're gonna set our, uh, well, first would put in the text of the Texas gonna be we'll just have this be text to and then our x y points. So what we're gonna do is we're gonna have text, and then we're gonna have an arrow pointing to some place and then it's gonna end where are text is so that we can kind of have an air pointing there and then we can have explanation text in a graph. So our X Y points are going to be, um let's have that be maybe 30 and five or something like that. And our X Y text coordinates are going to be, um, 35 5 like this. And now the last thing that we need to do to add an arrow is we have to add era props is what it's called. And the way that we defined that is we can say you have to have Carl it actually, addict. Um And now what we need is we need a face color. And so this face color, let's say let's have not be read. Um, and then we can do a little bit of padding and stuff at the end, But let's just run this, Um and so we see here, we've we've drawn this kind of little arrow. We can barely see it. So it actually starts at 30 and five, and it ends at 35 5 where our text begins, which isn't very far. So if you make this 65 for example, Here we go now, or arrows a little bit longer, which is nice. So the Arab starts at this X Y point, and it ends at the X Y text. This is the kind of custom text that we've put in here. Um, we have the face color of the arrow being read. Where we can do, for example, to add some extra padding is we can add something called shrink. Um, and this just pretty much add some extra kind of patting that corresponds to the coordinates. So if we add a padding a five, for example, we'll see that what we can't really see that very well may be less out of padding of 25 or something. All right, well, that doesn't seem to show up much either, but this is gonna pretty much just add some padding to the front and the back so that the aero doesn't really overlap with a lot of stuff, so that there's kind of this extra padding between our text as well as some initial points that we may have in front. Um, you can also add other features. So, like I said, this this annotate um there is a lot of stuff that you can do with it. You know, the very basis basics is just, you know, kind of adding this aero to a point in having some explanation text, You go into much, much bigger detail, you know, have huge arrows and have text inside, you know, um, transparent arrows and have, you know, like only outlines and, you know, being having how shaded and rotate. And you know, whatever else you can think of, you can do all of that. But like I said, that's a lot of stuff to go through. Will probably have a completely separate tutorial just looking at kind of the advanced annotation techniques. What's important to know right now is just that the annotation future is out there in case you may ever need it. Um, you know, even it's out there, And if you want to ask something specific and just look it up, um, and adjust depending on, you know what you need. But this is just kind of the basics of adding text. Would you seen here? You know, adding annotation, which is just text with extra stuff, and then we can also add the rotations to our ticks that we've seen. We can also want rotate our custom text, uh, and everything. Um, like that. So we can I also up into our text here, for example, the Kanada little rotation by 45 degrees. Like this. Um, so now we've got our text kind of rotated. Um, and so this is kind of all stuff that we can do. We see that it also rotates around the center. Um, So there's a lot of cool stuff that we could do with plotting. Um, yeah. So that's it for the third tutorial on my problem. I hope you guys enjoyed it, and I'll see you in the next one. 8. Adjusting Plot Sizes, Adding a Legend, and Saving the Plots: Hey, everyone. And welcome back to our tutorial on plotting with Matt Problem. This is the fourth tutorial, and here we're gonna be looking at adjusting figure sized, adding legends to her figure as well as eventually saving our figure. So what does that mean in practice? Well, right now, if you run the code that we got in tutorial three, we're going to see this kind of rather small looking figure. And what we want to do with it is we just want to make it a little bit bigger. Um, that's gonna be the figure size. We also want to be able to identify these different lines. So we want to have the kind of legend somewhere that tells us, you know, this this red line means this the screen line means that, um and ultimately we just wanna be able to save for the computer, saved the file or the figure onto our computer so that we can use it later. And so that's just kind of an image that we have on our computer that we can use later. So we're gonna look at first adjusting figure size now something that we're gonna need to know but that we'll look at a later and more detail to Is that everything that we're referencing here is to a certain figure. So as soon as we start, you know, calling these plt commands until we do a show, we're referencing the same figure. And unless we explicitly say that we're changing figures on DSO, what we can also do is we can also explicitly accesses figure before and through going into plt dot figure and in here we can actually change some of the properties of the figure. So all of these plt dot commands are gonna be on this one figure that we're referencing, so it's actually automatically created for us. And we can also change the general property of this figure to change for example, the figure size. So to do that, we'd have to go into the p o t dot figure, which is gonna access the figure that we're gonna be calling everything on until the next show command. And here we're going to go into fix eyes, which changes the figure size, and we can make this equal to. And then we can put in a custom size for example, 10 by five like this. And so if we run our code now, we see that our graph for our figure is actually a lot writer. Um And so that's what this this fix size here does we see this one here corresponds to the width, and this one here corresponds to the heights. If I changes, for example, to 10 by 10 then we're going to get a taller figure. Two. So here we can see that, you know, um, yeah, we can just scale are figure bigger. And then if you want, we can change our phone sizes and stuff to to adjust for that. But this really allows us also to see the graph a little bit bigger s so that we don't have to look at these. This small thing here, that's all compact. But we can also just scale on adjuster figure size to make it a little bit nicer to look at and maybe also a little bit more clear. Okay, so that's how we go about changing the figure size. Um, the next thing that we want to do is you want to be able to identify the different lines here and the way that we can do that is through adding labels and a legend. So let's go ahead and just start with our away team goals here. And we're just gonna go in here and we're gonna add, um we're gonna add another parameter, and we'll just do this on in the line. And what we're gonna add is we're gonna add a label now you don't have to this on a new line. I'm just doing it so that it kind of all remains in size, Um, of this box here so that we can see it, but you can just continue on the same line if you like. So we're gonna do is we're gonna add a label. And this label is what's gonna kind of pop up wherever we tell it to. And it's gonna have the corresponding color, and it's gonna have how it looks like. And it's just gonna show us kind of a piece of this of this graph or of the corresponding plot. And it's also gonna come with the label so that the people who see it or who read it can understand what, this um, we'll see that in practice again in a second. So We just want to kind of give a name to this graph. And so this is we'll just call this the away team goals, because that's exactly what they are. So that's the label for this plot for this plant here. Uh, we're also going to go on to a new line. Um, yeah, just so that we can kind of keep it all in this environment here. And we're gonna add the label here to be the home team. Gold is like this. So now we've added a label to each of our plots that we have two plots that occur. We've added a label teacher them. And what we can do afterwards, after we've added the label is is that we can go into plt and we can call legend. Now we're referencing the same figure. And so all this is referencing the same figure and not what this does is it creates a legend. So if we run this now, we see we've created a legend up here and we see that the dash green lines correspond to the awaiting goals which if we look up here, we have the green which are dash which correspond to the waiting goals. That's what this label ISS, and we have the dotted red line which here the color red and lifestyle, is dotted. Corresponds to the home team goes So that's what this label does. And this legend creates this legend with corresponding labels and just kind of puts it up. And the default location is up here in the upper right corner. But you can also change that. You can change the location, for example, to be in the top left. So weaken going to location and we can say upper left, for example. And if we run this now, then our legend has moved to the upper left corner. Now, we can also do bottom for brother with lower right like this which will move it to the lower right corner. We could do the same thing with the lower left. There's a lot of positions that you can choose from. You can look at them all if you want, but this is kind of how you can change this. That location default is generally up here. Um, it also worked well for us. So the upper right actually worked the best for us because there isn't anything up there so it doesn't really interfere with any of her. Plus, but depending on you know how your grass looked like in stuff you may need to move around a little bit if you like. And finally, we can also just go ahead and save the figure somewhere on our computer. So the way that we can do that is maybe just directly before we show it. So every time that we call a command, then it gets added to our figure. So we want to save the figure right before we show it, just because everything so that everything that we did before gets kind of saved into this safe figure. So if we called the figure save, for example, above this legend call than anything below this legend call wouldn't be part of the figure that we save. So we want to call this just right before we show it so that we get this whole figure, um, saved. And if we call it after we show it, then we were not really We can't really call the same figure anymore, because after we shone that we don't really have the reference to it anymore. Until we explicitly unless we explicitly create one. So But that's not what we're doing right now. So we just wanna save the figure directly before we show it, just to make sure that everything that we've created is actually part of this figure. So the way that we can do that is we can go into plt and we can call save Fig like this. And I would just put her name here, for example, my first figure, Um, like this. And if I run our code then are up but isn't gonna change a lot here that we see. But it's also going to save a copy in whichever directory that I'm working in right now. So wherever this coat is, that's where it's also going to save my figure. Now, we can also change the path that we want by, you know, adding half in the frontier or pending it to the back. Um, but a stewardess generate gonna save it like this. The normal format that you're gonna be saving in is a PNG, but you can change that by adding your own extension. So, for example, if I want to save it as a PdF, I can do here and just at a dot And at the pdf extension like this. And so if I run it now, my figure is gonna have the specific pdf format rather than the PNG that was created beforehand. Um, yeah. So this is how we can go ahead and save our figure. We can just change the format by adding our own custom extension if you want. You can explicitly also call the format later on as a separate parameter, but it's probably just easier to just generally put the extension there explicitly. Um, yeah, but 9. Creating 1-Dimensional and 2-Dimensional Histograms: everyone. And welcome back to our tutorial on plotting with map Ludlum and this tutorial we're gonna look at creating history grams one D as well as two dimensional history grams em. Yeah, So let's just go ahead and let's get started on. We're gonna just create history rams for home team goals as well as our away team goals and ultimately will also look at the total goals. So let's just go ahead and let's also take this space away here. Um, let's just go ahead and just start with the basic. So to create a hist a gram, we're gonna go into plt and to map pot Lippi plot and we're gonna access hissed. And here we could just input some kind of variable that you want to make a history and plot about. So we're gonna put in the list of the home team goals and then afterwards we can just go into plt dot show. And if we do this, we're just going to get a general, hissed a gram of the home team goals which looks like this. Now there are some things that are wrong with this. For example, you may notice that the bins are aligned nicely and all this kind of stuff. Um and so let's just go ahead and go and fix that first. So the first thing that we want to do is we actually want to change the number of bins that we have so that their align nicely. And to do that, we're gonna add a new property here, and we're gonna go and change bins, and we're gonna make this equal to, and now we can put a list here or something, but we're going to create a range, and we're gonna create a range, and this range is gonna be, let's say, eight. And let's just let's just see how that looks like for now. So we're gonna change your bins and we're gonna and let there be eight different bins that's that could be chosen from. And so if we do that, we see that they actually look a lot nicer now. So each been kind of corresponds to, um Well, whatever it is so like, the first been, for example, would correspond to the zero go scored the second, been would correspond to one goal. Scored the 3rd 22 and so on. Here on the Y axis is we could just see the corresponding number of goals that have been scored. And so we kind of see that it trends up. One goal scored seems to be the highest for the home team, and then it also just goes back down. We also see that there have been mawr two goal scorer than there have been zero goals scored for the home team. And so this is some of these things that we just read off from the history Graham immediately. Something else that we can do, for example, is we could add a, um, label to it again. And then eventually at a legend so we can go into label. And we can say this is the home team goals like this. Maybe we just put this on another line so they can see it. And to actually have this label pop up, we need to go into plt, and we can add our legend here like we learned in the last tutorial. And maybe while we're at it, we just also increase that figure sauce. So we go into plt, that figure and here we're gonna change the fake size to be. Let's let's make it. I don't know. I like 12 by eight or something. Let's just see how that looks like. All right, so that's a little big. Maybe we can scale it down eight by five or so. All right. So that looks better. Um, now we see we've got our kind of label here, Um, for the for the home team, goals and stuff we can also at maybe an x axis. So we can go plt dot exe label. And here we can put in goals scored and then the while able we couldn't do in pl Tito, Why label? And we can go. Number of goals scored. And if we run this again now, we just add a little bit of a bit more detail to our plot. So we see we've got this nice kind of history. Graham with bins and everything seems to align nicely said That's that's pretty great journal. You're probably after going to take care of these. He spends yourself just because we have the problems that we saw up here that there are no line nicely. You can also add special line statements by yourself so we can go in here and set the ally in property, for example, to be mids, which, if we run this, we're probably not going to see much of a difference. Or you can also change it to be left. Um, and so here we can kind of see that the lower end has been adjusted a little bit. And we see that instead of, um, instead of Arctic so artist a gram instead of its starting at zero, the left edge, the left edge actually now starts behind zero. And we see that the middle, for example, starts zero so we can kind of change things like this is fueling. You can use this alignment for that to kind of ship those around a little bit if you want, so you can also play around without, depending on what you like, what you need, what's easiest to read. Um, and so this is kind of the standards hissed a gram. Now, if we want to add two more data than this, and let's say we want to compare the home team goals as well as the away team goals on the same plot we can do is we can actually just do that by setting the X value so the X value is gonna be your data. And right now, we didnt explicitly need to say anything because we only had one date on. But if you want to put in another piece of data, we're gonna put those in in the form of a two bowl. So our exercise is gonna be the home team goals. That's gonna be the first value that we want a plot. The second is going to be the away team goes like this, then our bins, they're going to say the change the same. We also need to adjust our labels. So now that we have two data points or two data sets rather that were plotting, we need to adjust your levels accordingly, which is also going to be in the form of a list. So our first label is going to be haunting goals, and then the second thing is gonna be the away team goals like this. We can also add some spaces here. All right, um and so if you run this now to put this on the new line, we see that it's pretty much been done for us. So we've got the away team goes here, which are now appearing green. We've got the home team goes there, all appearing on the same plot. We can also nicely compare them. Um, we could see, for example, that for zero on one, it seems the waiting goals scored more zeros and once the home team. But once we go away, we see that the home team actually scored more. 234 and six, not five. So we consent kind of see a little trends off these props to just by comparing the size of these hissed a grand bars. Um, none of our labels have changed or anything. And we've just added this extra label here and a legend. Um, maybe one more thing that we can do is we can also look at the total goals so we can say total goals and we can just can captain eight, or to list so we can say it in total goals equal to the home team goals plus the away tingles. And so what this does is just adds Theo 18 goals list to the end of the home team goals. So that just kind of puts the two together. And now we can also plot the the total goal. Or let's call it total goals because it makes more sense and will also add the label total chuckles scored like this. Maybe we can also just put this on a new line. Um, all right. And so if we run this now, we see that we also put in the total goal scored. Everything pretty much gets adjusted for us automatically on scaling our labels here the same. Our legend is adjusted accordingly because we've out of the legend here, and colors have made different. So that's all done for us. And it's really cool. And we can just kind of compare everything and didn't yeah, have it all in one plot, which is really nice. So this is how we go about making one dimensional Mr Graham's. Now we can also make two D hissed a grams. So how would we do that? Well, we can go into plt and we can access hissed. But now, instead of just going into the hiss, which gives us a one d, we access his two d, and now we need to define X as well as why values on And so that's what we're gonna be plotting against each other pretty much. But we'll see what that means in second. So let's just have our ex data be the home team goals. And let's have our wide data be the away team. Goals like this and this. Let's just show her plot and let's just see what we get. Maybe we also copy and paste this figure size here so that also this figure will have the same size or our newest a gram. Um and so what we see here is we get this two dimensional. Missed a gram. Now, all of these dots are actually significant because these are the ones that we actually care about. Um, and all these blue spaces in between don't really tell us anything. That's just kind of been misalignment that we have in the very beginning. So we're also gonna need to change our bin sizes. Um, and so we can just look at the bins parameter again in this case, rather than having one put this on a new line to maybe that rather than just having one Ambon's parameter, because we only have one dimension here on going one dimensional kind of. We want to change, too. So we want to change the bins in this direction as well as the bins in this direction. Um, and that's because we're having a two dimensional hissed a gram right now. So the way that we can do that is through the form of a two bowl. And so we're gonna change Arbenz, and we're going to say, Well, the X direction is gonna be arrange eight in this case, and the Y direction is gonna be arrange seven. And so if we plot this now, here we see now that our bins are much more nicely aligned. So we don't have any of that extra blue spacing that we had in between on each bin is kind of just or each each. Yeah, Each been here is just kind of filled up, um, correspondingly so that we don't have extra weird spaces in between. Um, and you can kind of see where I got these numbers from. So this is we've got a range eight over here, which makes them accident value seven, which we got over here and the range seven kind of gives us from 0 to 6 um So that's just where we're getting those those numbers from. And you can also play wrong without a little bit yourself to see what's most optimal for me . For you. Um, generally, you'll probably have to change them unless you have high data sets and you can't really tell the little spaces in between anymore. But it's always nice to have these custom options to be able to do that. Um, so, yeah, maybe one more thing that we want to do here is rather than compared to this system, Graham, we can actually read off the wall. I access immediately what values correspond to About what? So we can see that, for example, here one goal for the total ghost Skordas above 100 maybe one or five, or something like that. But here in this color bar, we really have no idea. And maybe also, we should just quickly talk about what? What are we actually seeing here? So, on the X access, we're seeing the home tingles. And on the y axis, we're seeing the corresponding away team goals. So, for example, if the home team scored one goal, then we've got a hist a gram distribution of what the away team has scored. So that's what we're kind of seeing eso for each each kind of thing. Here, we've got another distribution that tells us, you know, like how Maney went, how many of these scores have, you know were 10 for the home team? How many of these were 11? How many of these were 12 on and stuff like that? So that's what this this two dimensional history and blot is actually telling us It's it's looking at And maybe it be nice if we just at the X labels in the while I was too, So plt dot exe level. We can make this the home team goals and then the peel t dot Why label? Why label? We can make the away team goals like this. Um, And while we're at it, let's just at the, um number indications kind of. And the way that we do that. So we see that we have different colors here, and these colors correspond to numbers, but we don't really know the scale, Yah. So to see that we go into plt and we add the color more like this and So if you run our code No, What we see here is we get this nice little color ball on the side that tells us what that I use. These numbers correspond to. So we see that dark Red corresponds to about 18. Then we've got dark blue, which corresponds to zero. And so we can kind of map these colors to these numbers like this. And we can see, for example, that when the home team scored one goal, there were about 14 matches where the away team scored Cyril's. There were about 16 maybe or 17 matches where the score was 11 Um, and so on. So that's how we can kind of read this two dimensional hissed a gram plot. And we've also got our ex labels and r y labels here. Um, yeah. So that's pretty much it for hissed A grams. We've seen the one d history Graham here. We've seen how to add one data value, but we also seen how to add several data values like we've done here so that we can kind of compare them on one plot and in the two d hissed a gram were able to compare two different types of data sets, and we get this nice kind of two dimensional hissed a gram distribution as well as the color bar so that we can actually read off what these numbers correspond to, where we're what these colors correspond to in terms of numbers. 10. Changing the Axis Scales: everyone and welcome to our tutorial on plotting with map, lot, lib and python. Now, before we move on to doing some or difficult types of plotting and some more intricate types applauding, let's make sure that we have all the basics covered, and one of these is also changing the scale of the Axis. So what do I mean without, for example, now we're just generally using a linear scale. So everything on the X axis and why access ticks are just kind of literally spaced. But we can also change our scales to be different ones, such as log arrhythmic scales, for example. So that's we're gonna look at now now. So let's try to start off and let's just import Matt Schlapp blip dot pie plot as plt like always. And now the first thing that we want to do is you just want to create some X and Y variables that we're gonna plot against each other just so that we can kind of look at these different plots. So let's just go ahead and create an ex list and a wine list, and these will just both be empty and then we're gonna make a four fresco for I in range loop and in this range, we're just gonna kind of upend the values texting. Why? Just to kind of have a a nice list of numbers for our X and Y values. So arrange left to start up negative. I don't know, 10,000 or something on debts go up to 10,000 and we'll just go normal steps. Um, and since we can only take into your steps, but we actually want to get some decimal values, we'll have our X and R Y values upend I over 100. So our eyes just gonna take on values between negative 10,000 to 10,000 were actually on Lee A pending I divided by 100 so that we can get some decimal values. So, for example, when we're at 99 or something, we're gonna get 0.99 and stuff like up. So that's that's kind of what were going to do here, and we're gonna do the same thing for why now, Of course, we can also just only use X and use X's are X and y variable, but let's just kind of keep it straightforward. S so that we can kind of see what's going on and will create the X as well as the white. Very bold. Okay, so, yeah, let's go ahead and let's just plot, um X versus why, for us Just to see what we get. And then let's just see your graph. So we'll just do that kind of standard plotting. Um, And if we plot exercise, why, we see, we just gotta get this linear plot ranging from negative 200 to 100 Just kind of straight of linear, Um, exactly what we expected. Um, no, What we can do is we can actually kind of change to the scale here, and we'll just kind of plot different examples. So if we want to change the scale and we're gonna look at the X scale So if you want to change this well, we can actually go into plt and access X scale, for example. And now here we can put in the argument of the scale that we want and depending on which argument we put in, we actually have different options later on. But let's just start with the simple linear case on. And so, if we were on this. We're actually not going to see a difference. And that's because the standard scale is linear anyway, so that doesn't really affect anything here. We could do the same thing for the y scale. And just also, I thought that as linear. And we're not gonna see anything different here just because it's the standard scale. Um, but this is how you can set it. And now next, let's actually look at some different types of scales that we can do. So let's just kind of keep this here is the base case. And now let's make a new plot And he we're gonna part expresses why again? And then we wanted to show it show like this. But now we're going to change our ex scale, and instead of having a linear scale, we're gonna have a logarithmic scale. And so if we run this now we see here we have our linear case, and here we have our logarithmic case. We can see also that are larger with me. Case actually doesn't go to zero or into the negatives on DSO that's taking care of internally because if we approach zero, then we approach infinite values and we don't want that in. Negative values are undefined. So for the logarithmic scale here, um, we see that we're kind of cut off to the closest value right above zero, which in this case, is 10 to the minus two because we're dividing by 100. So we've got 1000.1 That's about as close as we get to zero. And so that's actually where our scale or ex scale in this case cuts off our why scale is still fully defined. Um, that's because we're not changing the West scale, but our ex scale is getting cut off and we can change. For example, here change X two y and now we'll just get the same thing. But in this case, it will be for the y. So here, we see now are wise limited to being above zero. But our excess between 109 100 so x scale is still linear. But are y scale is logarithmic toasters Change this back to X if we dio. Also, if we also change our y scale to be logarithmic, for example, we just get a linear plot again, um, with different kind of end values And that's just because if we do a large block thought and our data is linear than, well, obviously got a linear plot again. But we can kind of see here the different tick values in the different scales that we're getting, So that's kind of where we see the difference. All right, so maybe we just take this out for now. And let's just deal with the normal, um lage rhythm on the X scale and they're extra extra parameters that we can change on. The first thing that we can do is we can change the base so we can change. Now. We're in base 10 right now, so we see that down here, we can change the base to be five, for example. And so the way that we do that since we're changing the X scale, we actually have to change the base X. If we're changing the life scale in here, we'd have to change the base y and let's change our base to be five and so similarly for why would change the base wide to be five since this is the X scale. So when you change the basics and so if you run this. No. We see, now we're plotting or an hour X scale is actually in base five. And so we kind of see that down here. If we remember before, we had 10 to the two as they're kind of upper limit. And now we actually have five to the three kind of as as their upper limits. So we've changed. The base that were plotting against on this standard is just based him. But now we've changed our base to be based five. Another thing that we can do is we can also change the number of ticks that we have in here . Um, So right now, it looks like we have about three ticks in between each kind of major points. Um, and we can change that using this substance X in this case and in the white cases be the sub swine. And here we can put in a list for the text that we want to have. So, for example, we can put in two and three, and if we run this now we see we only have to, um, two ticks here in between each kind of major take and these ticks Air Lage rhythmically placed accordingly. So if we have four, um, if we have 23 and four as our ticks will see that the spacing between them is not equal on this scale, but they actually correspond to equal spaces. Um and so this is kind of just the logarithmic takes that you're dealing with the kind of standard values. Um, if we change our face up to 10 for example, again, we're still only going to get three ticks in between now. So weaken also just increase our list, for example, to include five and six. And so, you know, get five ticks in between on. And so this is kind of how we can change the number of minor tics that we're getting in between each of the major ticks. All right, so that's it for log. Another thing that we can do is if we just pop this again. Um, we can change the X scale to be something called Sim Log, which stands for a symmetrical, longer rhythm. Um and so let's just see that graph first. And then let's talk about what it actually does. All right, so the symmetrical algorithm we see here goes into negative values again and what it does it it's literally a symmetrical, longer rhythm versions. So we've got this kind of symmetry going on here and around zero. Um, we've got our values to be approximated to a linear, so we can kind of see this linear region here, which happens around zero so that we don't reach these infinite values. We have this linear approximation but that when we go away from zero, we actually become lage rhythmic here. And similarly, we also become logarithmic down here. Um, no, we can also change our base again here. So, um, everything that we can do on the X scale is just kind of symmetric weakened else to do for the Y scale, just like we have appear will change X for wine. But let's just stick with the X case. So are basics. We can change to five, for example again, and that will change our scale accordingly. Down here on the general shape is still kind of without. We also see that our why is still linear because we haven't changed the wine. We can also change the ticks that we're getting. So our ticks here again, we could just do two and three right now we have it looks like no minor tics. Now we'll be adding to minor tics in between, which we can see here. Um, so this is very similar to the law algorithm. There are some extra parameters that we can put inside so we can change For example, the range of this linear approximation Onda. We can do that by accessing the length rush in this case of the V X And what that does is it changes the value of so if you just I'll just write that if we have Arlen Thrush X in this case, it be from negative 10 to 10 for example, will have a kind of linear approximation. And so if we run this, um and let's just wait for a graph we see here, we get kind of this this linear approximation going on in the in the region that we defined and so we can kind of change this linear threshold. In this case, it would be the X for the X value because we're looking at the X scale, but we can do the same thing for the Y value and that kind of changes where we want to have a linear approximation. So if we do this down to one, for example, um, that means our our range of having linear approximation is gonna be much smaller. So we can kind of see the difference is here and here of where we approximate our region to be linear rather than logarithmic. All right, so this is log symmetrical log, linear. There is one more thing that we can do. Um, Sophie Plot excesses. Why again, Um, and the last kind of scale that we can do is called a log It, um and this is kind of the inverse of the, um now one of the logistic function that you have in mathematics And what this gives you kind of gives you a, um again, Because either log a rhythm of a probability. So if you know what the log it is, then you'll know what this is used for. And if you don't know what it is, then you probably don't need to use it. Anyway, it's just kind of nice to know what the scale is. So if you ever need to use the luggage, then you'll probably Noah. Okay, I I know what it is now, and so you can train to the scale to be accordingly. Since we're not really dealing with probabilities, we only have linear values. If we use this right now, um, we'll see in a second. The graph that we're gonna get is not really nice. It doesn't really tell us anything. It's just zero. Um, we can kind of see here the scale that we're getting is between zero and one. And that's because we're dealing with probability values, too. So, yeah, um, this is this is kind of the different scales that we can look out there really useful. Um, And if you need to use any of them than it's just really nice to have this reference to kind of know that we can use them, we can also change these based parameters and stuff. Um, and depending on what kind of plus you need to make it may be nice. Rather than having to adjust your data or something, you can just adjust the scale that you're working with. Um and that makes plotting a lot easier. Um, yeah, right. So that's it for changing the access scales. And I look forward to seeing you guys in the next tutorial. Hey, guys. So if you want to keep up with Almond Mr Content, you can also look at my YouTube channel and I'm gonna regularly posting their new videos about new things that I'm going to be doing. I'll put a link in the description teacher videos, looking towards my YOUTUBE channel. You can see all the stuff that I'm gonna be working on. It's gonna have some of the courses that you know from here, but maybe also some other material. So you just keep up to date with everything that I'm gonna be doing. 11. Course Outro: Hey, everyone, it's Max and I just want to say congratulations on finishing the course. I also want to remind you do make sure to go through the exercise in the project section and also think about ways to use data digitalization in your current life. So think about what is some of the data that you're currently analyzing And how can you visualize it? Because a lot of times when you visualize your data, a lot of patterns suddenly become very clear because we work in a very visual manner. Also, look at visualizations that you already made and see how you can improve those by making it more clear throughout in things like titles, text labels and other types of annotations.