Visualize Matrix Python | Plots In Python With Numpy And Matplotlib


Subscribe Here





Plots In Python With Numpy And Matplotlib


We’re gonna work through some plots in Python, So come to the course website. Come to AP minor comm Ch E 263 and the one that we’re gonna be working on is under the homework and then. If you go to homework 9 you’re gonna see, you know, this is the printout of that. You can also grab the files right here, and that will give you an. I pi thon notebook. If you just open that up, you’ll see it’s right here. You want to make sure you extract it, OK? Extract the files. And then you can start working with it from there or you can move your ipython notebook somewhere else like the desktop. Okay, So I’m gonna open up the Jupiter notebook. Okay, so I just search for Jupiter. It’s gonna come up with this black command, prompt screen. You just go ahead and minimize that. Don’t close it, but you just need to minimize it, and and then if you need to you can navigate, you can navigate to the right place. I’m just gonna go ahead and select that it will open it up. This is going to be a template that we’re gonna use to do our problems right here. Okay, but we’re gonna start with Problem 1 We want to create a plot of e to the negative X Times Sine 4x + e to the negative X cosine of 4x from 0 to 5 and we want to change the line color, too, for the first ones red and set them to blue and just aligned with two to add a legend like X label Y label and plot title. OK, so let’s go ahead and start. The first thing that we need to do is import a couple different packages, and these are just gonna be standard imports. You’d almost copy. This section from, you know, from this is kind of a boilerplate for other problems as well, so we’re gonna import numpy as NP that will help us do arrays and the data processing. The next one that we want to import is import that plot live. Okay, so it’s a dot pie plot. Okay, so it’s a specific matplotlib pie plot and will import that as PLT. Okay, so we just shortened the name, so we’d already use map lot of that pie plot every time we want to use this, We can just use PLT, and then we’ll also do import random. We’re going to use that later and then for the notebooks and this is not required. If you’re going to use spider or you know, just the program that you get from Python org. It’s just only in this web page environment. You need to map, plug the in line and I’ll show you the plots here in in the Web page. Okay, so then I’m going to let me go to insert a cell below. Okay, so I’ll go ahead and run this. Okay, so that has run and now. I have all of those imported. So now I can use things like NP. Zeros, you don’t mean to make array of two. Okay, so things like that. I can start using NP or PLT packages. Okay, so the first thing I want to do is create an array X. Okay, so I’m trying to plot trying to plot these, but I need to go from 0 to 5 and I’m gonna do the linspace from 0 to 5 and create a hundred points. Okay, so let me go ahead and do that. I’m just going to ctrl. Enter there to get rid of that, okay, and then if I print X, I can see that I have a hundred points between 0 and 5 They’re all equally spaced or linearly spaced. Now, if I again if I need to do any kind of help on this, I and P linspace. Okay, and that’s going to print out a help. Okay, so it gives me the right here. This this Linspace start/stop and then the number of points that I want, so it gives me a little bit of help on linspace. You did that with an e function typically, and it’ll give you the help. Okay, so let me come down to the print here. I’m going to delete that. I know that’s already and created now. I want to come up with Y and with Z. So I just want to store these eat, and I say negative X sine 4x I want to store that in the variable. Y okay, so I’m going to do. Numpy signed 4 times X. Okay, times, numpy exp minus X. Alright, so so that is going to give me some? Y values. Okay, so they’re there. Those are the values that we’re gonna want to plot. And then if you just go and copy this, let’s make a Z as well. Okay, hold on, look more except okay, so now I’m gonna do Z and then I’m just gonna change this one to cosine instead. Okay, so now I have my day two XY and Z. But, you know, looking at these numbers doesn’t really tell me, you know, it doesn’t really show me the the data very well so now. I want to use this PLT package. Okay, so sometimes what you do. Is you first of all, just create a figure or you can just start, you know, using it. If you have multiple figures, you can say figure one, and then if you want to create another figure, you can do figure two figure three, or if you just do this blank right here. I’ll just create a new figure for you, and then you can start using it. Okay, so then. I’m going to plot. Okay, so I’m gonna do Plt Dot plot. And if I just do X comma Y okay, that’ll be give me just a basic plot here. Okay, so you can see. I had my X and my Y values, and then if I add Plt plot X comma Z and it’s gonna put Z on there as well. Okay, so I have the two. I plotted those two. You can see the kind of an exponential decay here. I multiplied by e to the minus X Times sine Okay, So if I only had, let’s say only had this. Okay, and this kind of makes sense because if I only had that, okay, you’d see it kind of goes down like this. I’m multiplying the sine or the cosine by the E to the minus X function. Okay, then it gives me something that the Kays down and decreases the oscillation So that that kind of looks right, but let’s add a couple things just to kind of make this plot. Look a little bit better. We want to maybe change some things about this, lets. Make one of them. You know, a red dashed line, for example. Okay, so there’s a red dashed line. Let me do something that’s like. Maybe add a legend. Okay, and I can either Add it here or this might be, you know? Y comma Z. Okay, then I put that there, all right, I just create the legend, and then I label each of these so this might be label, you know, and then equals, and I’ll say this is my Z, or I could say E to the negative X Times sine of 4x Okay, And then I’m going to put label. Okay, let me do. I think. I’ve got those mixed around. I think this it might be co-signed. Okay, cosine and then sine, and then, oh, I made a mistake there. Let’s see label is not defined. Hmm, okay. Oh, you know what? I need to do equals there. It is, so I’m not a pro, Not the parentheses just the equals and then in quotes. So it’s gonna be a string label equals a string. Okay, and then let me just check and see if this works and I put it in dollar signs. It might do something really nice, which is put it in latech form. Okay, which is makes it look more like a math equation, okay. I’ll get rid of that. Yee, there it is so so it looks just a little bit better, even if I put it in dollar signs, and that’s gonna format it into something that might look like it. It is in a textbook. Okay, so there. I go okay, so E to the minus X sine of 4x all right, and then let’s add some things like a X label and a Y label. All right, so X label might be something like X and then Y label to say that some value. Okay, So put this X right down here to put value right here. We have our legend just starting to look a little bit better, but lets, uh, lets. Adjust the width of the line. Okay, so let’s do line width. I’ll make this one just a little bit wider. Okay, let’s say I want this one. Just a little bit wider as well. Okay, so there’s a couple of different properties that we can adjust. You know, these are some of the most common ones. If we want to save this as well, we could do. Plt, save big. And then I can call it something like my big year. Dot PNG. And if I run it, okay. It’s gonna save that figure right here. Okay, so there it is. There’s my figure saved it as a PNG file. I can put it in something like Microsoft. You know, let’s do. Powerpoint. Okay, there it is, so if I create a blank presentation and I can then throw that figure into the presentation and then so that looks nice. You know, as a nice kind of looks like a Well. It’s a PNG big ear right there that we saved. Okay, so I’m gonna throw that in the trash. Come back to my ipython notebook. Okay, so just a review created our data created this new figure. We’ve plotted these to change some of the properties there and give it a label line with change the color of it, you know, change the style of the line as well, so there’s a number of different options there. X label viable legend. You can also do a title Plt title. My plot, okay, and see, so there’s a couple different things you can do with these these scatter plots, Okay, So the next video that I’ll show is going to be on problem. – we’re gonna do some subplots problem. Three were gonna go through, you know, we’re gonna just change some of the you know these. XY and Z data. And then we’ll change the marker sizes and other things. The problem for we’ll do some bar charts and pie charts as well.

0.3.0 | Wor Build 0.3.0 Installation Guide

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

read more