 And hello everyone, welcome to Matt Plot Lib getting started in Python with me, Tokyo EdTech. So let me first give a quick shout out to my channel members, Kevin, who becomes our first paddle member. Thank you so much, Kevin, for three months of support. And also I want to welcome to our second month, Snakes members, Finesz. Thank you so much for your support and everyone else here on the channel. And I'm not sure if I said in my last video, make sure I want to say hi to Chris and Old School Coder, check out Old School Coder's YouTube channel. Today on my channel, I'll be talking about the Matt Plot Lib Library. Just the absolute basics to help you get started. This is a pretty big library. It does a lot of stuff. I'm gonna show you just a tiny little piece of that. So the first thing we have to do to get started is we first have to make sure that you have it installed. Okay, so what you would have to do to test this is go to import mattplotlib.piplot. This is, we're gonna be using the piplot section, I don't know how else to put it, of Matt Plot Library. I'm gonna import it as plt. So when we do import something as, we basically change the name. And so this is a little bit of a convenience for us. So I'm just gonna go ahead and run this and see what happens. Okay, so program exited. And you see it says no module named Matt Plot Lib Fount. Okay, so this tells me something has gone desperately wrong. Matt Plot Lib. And I'm gonna go up here, just check my build commands. Okay, we are in Python three. So let me go ahead and test this. I'm gonna go down to the terminal here. I'm in Genie. And I'm gonna say pip. I'm gonna try pip install Matt Plot Lib. Okay, pip not found. So I'm gonna try pip three install Matt Plot Lib. And we should see, oh, okay, there we go. I didn't have installed, I don't know how that's possible. And so you can see it's actually installing a bunch of stuff, okay? And so it's done a bunch of things. And that's how I've installed it. I'm actually glad that that happened. So you can see the install process. And I'll put that command down below. Actually, I'll put it up here too. So I typed this in the terminal. And this should work on Windows and Mac and Linux as well, which is what I'm running. So it was pip three install Matt Plot Lib. Okay, and if that doesn't work, I'm not quite sure what to tell you. So I'm gonna go ahead and run this again and see what happens. And basically nothing happened. Exited with code zero. So that tells me that there were no errors. So this kind of gives me an idea that hey, maybe this worked. So basically, Pi Plot is a kind of an interface for the Matt Plot Library that helps you to make simple charts. It's not as powerful as the full thing, but it's good for beginners and getting started. So I'm just gonna try it, one of the commands. They're gonna try plot.show. Let me just see what happens. And I'm gonna go ahead and run that. And did anything pop up anywhere on my computer? No, it did not. Okay, so it ended, I think. Okay, so that's not what I expected. So I think maybe I have to actually go ahead and add some data. So I'm gonna go ahead and add some data and let's just go ahead and add, say, some scores. So let's say we've got our test scores. We're gonna 35 and do very well. Then we did much better. We got an 89 and then we suck back down to 67. We had a good day and then we started getting A's for that. So what I gotta do then is I gotta do plt.plot scores. So I'm gonna go ahead and run that and see what happens. And there we go, fantastic. Okay, so that tells us a little bit. So here is the absolute bare, bare, bare minimum for using this particular program. So we need to create a list of values. We need to plot those values. So notice I use scores and scores here. And then we use plt.show. And then what happens is it pops up this really nice window for you. And you'll see, so zero. So this is my first score because remember they start list indexes start at zero. So that was the 35. We, then I got an 89, then a 67, 95. And you can see how it went out there. So you'll see a couple of options here. Now on some computers you'll see it down below on why it happens to be up here. So I can click that and I can pan. Okay, so I can look around in case things, I wanna move off the scale. I can click here to zoom in on a section of the chart. And I'm not sure what this one does. Oh, I can edit that. That's pretty cool. I didn't think I could do that. That's pretty cool. And I can also save this onto my computer as a PNG file, which is pretty cool. And I'm gonna show you how to do that programmatically later. Now something to keep in mind. While plt.show is visible on the screen, this program over here has stopped running. So if you're gonna put this into another program, it will stop until I close it and then the program will continue running. Now in this case, of course it ended because I'm at the end. So that is the basics of it. So what I wanna do is I'm gonna show you a few little tricks, a few little things to make your charts look nicer and then kind of let you have a play with it. So something I might wanna do is I might wanna add a title to my chart. So as I was mentioning over here, I'm using the pie plot interface of this library. And so here are all the different functions that you can play around with. Now I definitely do not know what all of them do. I'm gonna show you just a few of them. Now obviously we've used plot so far and we have used show. So a couple of things. I'm gonna go ahead and try plt.xlabel. And I'm gonna say call this score number and do plt.ylabel and that's gonna be percent. What's it called, percent? So I wanna test that because I'm doing this from memory, so I could be wrong. I'm gonna go ahead and run that. And cool, that was correct. So you can see now the xlabel down here is score number and the ylabel over here is percent, which is pretty cool. Now one thing, in this particular case, we know that, you know, because as we're doing percentages, it's gonna range from zero to 100. And because we only have a range, a low of 35 and a high of 99, it's using that as the range. So what we can do is we can use something called ylim. So the ylim, it's I guess you'd say, and that's gonna be a list. I think it could probably be a tuple, but I haven't tested that. So it's gonna go from zero to 100. And note, I'm using the little square brackets here, not round brackets. Again, may work, may not haven't tried it. So I'm gonna go ahead and run that and see what happens. And you see here now, zero, which is the zero, and 100, which is the maximum value. So that gives us the ability to control the range of what we see. And we could do the same thing. There is an xlim, which does the exact same thing for the x-axis. Next thing we might wanna do is when we plot, we may want to label that. So in here I'm gonna put, oops, label equals scores. And this could be, well, we'll leave that for now. I'm gonna go ahead and run that and see if anything happens. I always spell label wrong, unfortunately. Let's go ahead and run that. And notice how we don't really see any difference here. So this is used, maybe used other places. The only place I know so far that it's used is in the legend. So you'll see there's a legend method here. So what I can do is go ahead and put plt.legend. And it will automatically put a legend onto our chart for us. Okay, and there you go. So you can see how we've got scores and a blue line, which is kind of cool. Now, something we could do here is I could say, I can make another list of scores. And let's say we're comparing two students. So let's say we put this one and then I didn't do quite as well on that one. Did really well on that one and then just dominated, just perfect scores. And then so what I'd need to do is go ahead and just copy this. Okay, so I'm gonna make this scores two, which I usually don't recommend. So let's say this is Bob and this is Sue and Sue has done very well. So I'm gonna go ahead and run that. And you can see in here how we've got now scores and scores two. You can see how the legend has moved actually. It automatically moved, I guess, because there wasn't enough space there. And you can see now, because this went up to 100, we don't really see Sue's scores. So what we might wanna do is come back over here and make this 101 so that we can see that. And we go ahead and run that again. And my computer has locked up. So probably it's still recording. It'll unlock itself in a second. Yep, there we go. Maybe. There we go, fantastic. Okay, so let's go ahead and run that again. Yeah, report a problem. Yep, I don't need to report it. Don't send. So go ahead and run that. This happens a lot with OBS. And not a lot, but often enough that it's annoying. So probably I'm gonna try it one more time. And there we go. Okay, so you can see now because I changed that 100 to 101, I can now see the line there. So you can see how it has a legend. It has some default colors. And you can put multiple plots onto one chart, which is really, really cool. Now, we're using plot.show. Now I can also use, let me go back to here. I think it's plot.savefig. Yeah, there it is. Okay, so there's a function called savefig. And there's all kinds of options here. I'm just gonna show you the real basic thing. So instead of showing it, where I could do both, I could say plt.savefig. And I can just call it figure one, png. And as far as I know, it saves in pngs. So if I run this, now this is still gonna pop up. I'm gonna close that. And then if I go into my files, and where does that, where did I put that at? Okay, so my Python file, I can see it is saved on my desktop. So if I go to my desktop, I'll also see figure one.png. That's really cool. So this is something that I can put into an assignment. So I can put into a chart or whatever I need to have that used for. So that's the basics. That's basically it. That's kinda how you do it. Now, there's this other cool thing, and I'm gonna go back to the plt. Pyplotplot, let's see here, Pyplotplot method. And what you can do, if you don't wanna use the default colors, you can do this really, really kinda cool techy thing and format and use what's called a format string. Okay, so the pattern is marker, line, and color. Okay, so the marker is where each data point is. So for example, we've got a circle marker. So what I would do here is I would put quote, oh, quote, comma. And let's say I wanna put a, let's see, let's do a triangle up. So that's the up thingy, up tick, up carry. And I'm not even sure where it is on my keyboard. So, I actually don't see it here anywhere. So I'm gonna skip that. I can scale, copy it. It's gonna be on my keyboard somewhere. Control copy, but I wanna make you guys wait. Where is that sucker at? Yeah, there. Quote, comma. So I'm gonna go ahead and run it and see what the result is. Which is pretty cool. So you can see now I've got scores is a blue dot. Scores two is a little orange triangle. Now, I lost the lines. So part of this formatting, it's marker, line type, then color. So if you're gonna use the format, you need to tell it what line style to use as well. So, a colon is a dotted line. So I'll go ahead and use the colon. Let's go ahead and test that. Okay, that's pretty cool. So now you can see we've got circle markers for scores. We've got triangular, vertical triangular markers for scores too. And the final thing we can choose is color. Now, these are the default colors, but apparently you can use these as well. I haven't tried that yet, so I don't know how it works. So I'm just gonna stick with these. So I'm gonna go ahead and make the first line green and the second line red just to test it out. Oops, wrong. Go ahead and hit F5. And you can see now how the colors have changed. And again, I can still do all those things that I was talking about. I can move around. I can zoom in. And I can see, you know, if there's a lot of data, I can zoom in and see kind of what's going on in my data. And then once I do this, I can save it. I believe it will save the figure. We'll test it. Figure one, we'll say zoom. So I'm kind of curious about this. And zoom. So I'm gonna go back to my desktop and see what it looks like. I'll bring that up for you. And figure one, zoom. And it did save the zoom version. So I'm not sure how to do the zooming programmatically but I never tried it before. To be honest, I just kind of really started using this, but it's so cool. It's so easy that I thought I would share this with my viewers, because I thought you guys would be interested in this as well. I do wanna try one more thing. I haven't done this before, but I saw it done. And let's say we have, instead of scores, we have temperatures. Okay, and I'm gonna take this out. And I'm gonna take that out. And I'm gonna go ahead temperature. Say Tokyo temperature. Because I live in Tokyo. And I'm gonna call this temperatures. Now, let's go ahead and pop over the internet real quick. And we'll say Tokyo temperature. And see what comes up. Okay, there we go. So you can see we got seven, eight, 12. Now this is all Celsius. Sorry for American people. I know you guys aren't down with the Celsius thing, seven. So I'm gonna put seven, comma, eight, comma, 12, 15, 10, nine. And what's next Monday gonna be nine. So we have nine in a row. Not a huge amount of variation. So let's stick with that. And I'm just gonna go ahead and run this. And make sure it's still working. That did make a few changes. Now you can see how we still got zero to 100. Now in Celsius, 100 is boiling. So we probably don't want it to be that high. So let's just go ahead and put 50. So it rarely gets above. It doesn't get that hot here, but I have had some 40 some degree days. So this is a bit more accurate. Now what we wanna try to do, and again I've seen it done, I haven't tried it yet, is I wanna change the zero, one, two, three, four, five, six to, let's see, I can't go over, that's not what I wanted to happen, to Tuesday, Wednesday, Thursday, Friday. And I think how that is done is like this. I'm gonna add an extra set of brackets. And then I'm gonna put in here, Tuesday, Wednesday, Thursday, Friday, Wednesday, Wednesday, Saturday, Sunday, and Monday. Now notice it is a list with two lists inside of it. So it's a multi-dimensional list or multi-dimensional rate of what you wanna call it. And I think this will do what I want. I'm not sure, fingers crossed. Yeah, it didn't work. Okay, so I'm gonna go over here and just kinda, again, this is something I probably should have tested ahead of time, but I was like, yeah, how hard can it be? Let's see here. This is where I wanna go ahead and Google, I'm gonna say pie plot. And I wanna say label x axis, label x axis data point. I don't know, I'm sure I'll have to put it. Label Python data points on plot. All right, okay, so, hey, hmm, hmm, hmm. Interesting, okay, that was a little bit more complicated than what I'm used to. So, I'm gonna go back to here, just see if that, I'm gonna go ahead and unlabel that. I'm gonna put temperatures, I'm gonna call this labels, just to see what happens. And temperatures, labels, who knows, let's see what happens. Yeah, I wasn't happy about that, I thought. Whoa, that is not what I wanted. Okay, so I got Sunday, Monday, Tuesday, Wednesday over here. I got the numbers over here, so let's go ahead and reverse those. All right, live and learn. Labels, temperatures. Oh my gosh, there it worked. Okay, so that is more up to speed. I know I've seen this other format, but I'm not sure why it didn't work in this particular case. But yeah, there we go. Okay, so, you put your labels and then your values. So, x comes before y. And you can see now I've got Tuesday is seven, Wednesday is eight, Thursday's gonna be 12, Friday's gonna be 15, et cetera, et cetera, et cetera. And again, so you can see how we get a very nice chart out of this. And if I go back to my desktop, because I still have the saving line in there, if I go ahead and open up figure one, and now it has saved it with the proper net. Now I know it's not a score anymore, so I should have fixed that. Let's go ahead and fix that and make it look nice. So the x-label should be day. Day. And the y-label should be temperature. And I'll go ahead and put in Celsius. Alrighty, and one more time. Just take a look and see what we've got. Okay, temperature in Celsius, day of the week. And there we go, fantastic. So that is a very tiny, tiny little piece of the Matplot library. You can see how there is some really amazing things are possible. If you see some of the examples, there's a ton of various just methods and things here you can play with. It's really, really impressive what is available through this library. And yeah, so hopefully that'll help you get started. That's about what I know so far. And so for my needs so far, that's about all I need. And then as usual, I'll put a link down below to the code. You can kind of download it and play with it. And yeah, so click like, subscribe if you haven't subscribed. And if you're able to consider becoming a channel member and supporting the channel directly, like these fine folks here. Thanks so much. Yeah, keep on coding. Take care.