Python 3 Programming Tutorial - Matplotlib Graphing Intro

sentdex · Beginner ·🛠️ AI Tools & Apps ·11y ago

Key Takeaways

This video tutorial covers the basics of Matplotlib, a popular graphing module for Python, including installation, importing, and creating basic plots. It demonstrates how to use Matplotlib to create plots, subplots, and customize graphing options.

Full Transcript

hello everybody and welcome to another Python 3 uh tutorial video and also the beginning of a bit of a minseries for matplot lib um if you want to know even more about matplot lib after this series I will just say I've got a very extensive matplot lib series on my channel it is in Python 2.7 uh but aside from print functions and then also the difference between try and accept uh the code should be completely portable over to Python 3 my goal here is just to show you guys some quick basics for matplot lib uh and then move on but if you want to know more about customization maybe uh fancy graphing and charting and all of that definitely check out that other series but here I'm just going to show you a lot of the basics Now map plot lib is not a part of your standard Library you will have to download it it is a thirdparty module uh luckily for everyone this should be very simple to download um but I suppose if you're on Linux or something like that it might be a little more tedious but actually downloading modules on Linux is very simple downloading them on site Windows is is very challenging sometimes um but luckily uh I'll show you guys here uh that is not too bad so uh let's go ahead and get started uh the first thing I want to show you guys is first of all um the website is matplot li. org is the official website for this you can come down and go to the matplotlib downloads page and you can actually you'll find that there are uh executable downloadable uh files for you to install matplot lib on your system now we're actually running on Python 3.4 and for whatever reason they have not updated uh mpl.org to include Python 3.4 um and last I checked you actually can't even run three because it's going to look for you know cpython 33 not 34 so that won't even really work but you could come here also and download The Source you set up.exe or just yourself move the files but that's obviously some of a challenge for some people so we're not going to do that uh instead we're going to come over here to this website's um this I'll put the link in the description if I forget someone remind me I've been pretty good lately about remembering to put uh the links in the descriptions but I like to forget sometimes so come over here and this website I highly suggest you just bookmark this website anytime you want to install something for python especially if you're a 64-bit python user you'll find that a lot of times you can't get uh 64-bit versions of modules inherently uh but what this guy does is he maintains his page um and adds exe installers uh for 32-bit and 64-bit and also as you'll see he's even updated some of them to include the proper version or the current version so for example we can go find and search for matap plot lib and here it is so we can click on that and it comes down here and we're at the matap plot lib now as you can see there's a ton of stuff here what I'm interested in and what you're interested in most likely at least if you're watching this video right now now is going to be either this one right here for 64-bit or you can come down here for the 32bit um actually this is what you would want here for 32bit now um I already have it installed so I'm not going to reinstall it but take note up here all of the things that are required uh or it says requires I think it really means like if you want to use every part of met plot lib you need all these things um I just suggest you download numpy for sure date youtil Pi TZ P parishing six and then oh okay they do say optionally foot in mouth um yeah you should be able to just not download any of these there I don't see any reason why you would need these uh at least for now so anyway download you know just just hold down control click on you know the version of map plot lib then click on day you to pz piping 6 and then you should be brought to each of those right because of the way that we uh click them download those install those you'll be ready to go so once you're so do that pause the video now while you're installing it if you don't have it uh and then pick back up so I'm done with that now let's go ahead um assuming you've got everything installed um we're ready to actually begin so first we need to import M plot lib now generally uh for just basic plotting we use what's called P plot in M plot lib so really you want to do some do the following so uh we'll come up to the top from M plot lib import pip plot and you could stop here but most people will import pip plot as PLT so you'll be seeing a lot of example code probably if you're ever like looking up how to do something you'll see people use PLT that's why same thing with like numpy people use NP it's just what people do now um the next thing that we would want to do is pt. plot and then in here you can you plot x's and you plot wise so um you could just plot a simple you know five seven so 5x 7 is y um but let's actually make lists out of this so we plot X as a list five 6 7 8 let's say and then Y is a list 7383 okay so what this does is it generates this plot and it will draw them onto this plot for you but you won't see anything if this is all you do you have to always end with a PLT show and later on you might get the idea that you want to make live graphs or graphs that update um and it's important to understand how this actually works because plot just kind of puts it up there and then actually I use the wrong word but you've got draw which actually draws it onto the figure and then you have to reshow uh to actually update the figure so just keep that in mind for way later down the road but just understand that this plotting it does not actually make the graph show up it just kind of stores it to memory what it ought to look like and then then plot. show brings it up so with that let's go ahead and save and run it and up Pops the following graph so as you can see we've uh made a whole lot of progress in very short time uh we've got a nice window here so you've been through the teiner tutorial so you can uh maybe um appreciate what we have going on here so we've got this figure and uh I could be wrong but I'm almost certain that matplot lib is actually generated all with tkinter so a lot of people ask ask um ask me to do a tutorial on how to put matplot lib into T hinter and sometimes I just want to respond and be like look at the documents for M plot lib because that's exactly what map plot lib is doing anyway so because like these are buttons you know these are buttons that are added in by teer and all that so anyway moving on uh so we've got a chart um I guess it would be kind of helpful to run through all of these options real quickly for you guys um so the first one is home now I can't really show you much about because we haven't done anything but it will reset your view to the original view that you were looking and in fact let me bring this over like this at least so that's home um then you've got the forward and back so I guess the first thing we should do let's zoom in first to get a feel for everything so this is a zoom so you get this little button and you can click and drag and you basically like zoom into that spot um so then home we're reset back to where you you know the original view so let's zoom in one more time and then you have these buttons here which is forward and back so let's zoom in one more time and we're like oh man it's too close we're not seeing anything so you hit the back arrow and you go back a little bit but let's say you misclicked and you went back twice darn it you want to go back forward again so you can click the forward arrow and get back again uh this one is just so you can kind of like click and drag and pull this thing around it looks better probably if you're in home but you can see that you can just click and move it around um and then finally well obviously this is just to save the figure it's going to by Nature oh this one saves as PNG um let see I think nor in Python 27 the default is like this Tiff and it's really annoying but looks like they've figured it out and now it's by default PNG anyway that's how you can save the figure that you're looking at to like an image file or or actually they have quite a few different file types finally configure subplots um You probably will stop using this and you'll actually be coding it into your script but it's helpful to know um this is just distance right on the side so left how much distance on the left do we want to allow for how much distance let me move this up how much distance on the bottom do we want to allow for right top and then uh w space and h space you're not going to be able to see that right now it's when you have multiple figures or multiple plots on the same figure um so here is your figure right and then this is a a plot basically and if you have multiple plots it's a subplot so this will be you know the space on the sides of of all the plots and then this will be the space on the top of all the plots again you probably won't find yourself using this too much um besides just for testing so if you generate a plot with say 15 figur or 15 plots on it um you might you got to like watch your mouth when you're like talking about mlot Li and a lot of coding stuff man because you want to use specific terms and it's not you you think of a figure like in textbooks they always refer to like each little thing as a figure but here a figure is the entire window and then you've got the plots within it anyway keep want to colum figures so I'm trying to trying to be careful but anyway when you have multiple subplots on there you might use this to be like okay well I want to hardcode it to always be left you know 06 bottom whatever you know and so on so you'll use it maybe there but eventually you'll start like hard coding in these values because you can set it in your script what you want these values to be they just happen to have a default so uh anyway that concludes uh the intro to M plot lib there's a lot more to do uh in this this little minseries again there is even way more that you can do than what I'll cover here but uh we'll get you guys at least uh started on Matt plot lib so anyway that's going to conclude this video stay tuned for the next video for a continuation of Matt plot lib if you guys have any questions or comments on these three lines of very complex code feel free to leave them below as always thanks for watching thanks for all the support and subscriptions and until next time

Original Description

In this Python 3 basics video, we cover the intro of the Matplotlib module. Matplotlib is one of the most, if not the most, popular graphing modules for Python. Here we show how you get it, install it, and put up a basic plot example. Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/ Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M http://seaofbtc.com http://sentdex.com http://hkinsley.com https://twitter.com/sentdex Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

This video teaches the basics of Matplotlib, including installation, importing, and creating basic plots. It covers how to use Matplotlib to create plots, subplots, and customize graphing options. By following this tutorial, viewers can learn how to use Matplotlib to visualize data and create informative graphs.

Key Takeaways
  1. Download Matplotlib from the matplotlib downloads page or using pip
  2. Install the downloaded file on the system
  3. Import Matplotlib using `import matplotlib.pyplot as plt`
  4. Use `plt.plot()` to create a plot with x and y values
  5. Use `plt.show()` to display the plot
  6. Use `plt.figure()` to create a figure and `plt.subplot()` to create a subplot
  7. Configure subplots with left, bottom, top, and right space
💡 Matplotlib is a powerful and flexible graphing module for Python that can be used to create a wide range of plots and graphs, from simple to complex.

Related AI Lessons

Up next
How to Open HPL Files (HP-GL Plotter)
File Extension Geeks
Watch →