Pandas with Python 2.7 Part 7 - 3D Matplotlib Graphs

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

Key Takeaways

This video demonstrates how to create 3D graphs using Matplotlib and Pandas in Python 2.7, showcasing examples of plotting price, high minus low, and volume.

Full Transcript

What is going on everybody? Welcome to another Python and Pandas tutorial video. As you well know, all the cool kids plot in 3D now. Uh so now we need to teach you guys how to do it. So with that, let's go ahead and get started. So we have uh we do need to have mapplot lives piplot still but we also have to import um mplore or actually rather from mpl dot or un_toolkitsplot 3D import axes 3 capital D. Now um that's why I don't think it'll work with pandas. If anybody knows how you can plot 3D with pandas, uh, feel free to let me know. Pretty sure you're going to have to do it this way though. Um, we can leave all of this other data here except all the plotting basically. So, we'll just do that. And let's get Well, we can leave plot show there, I suppose. Now, so let's say uh we want to compare maybe price to the high minus low and then see if there's any correlation between the high minus low and and price visually. Okay. So, um don't know anybody that does this. Uh but I just want to show you 3D plotting with the data set that we're using. So, we're going to say uh 3D equals plt.figure empty parmms.g G C A and then parenthesis projection equals 3D D. And basically what this does, oops, put quotes around that. Basically what this does is it notifies that hey we're going to plot in 3D. Now the next thing that we want to do is we're going to make a scatter plot. So we're going to say 3D.catter and first we're going to say df.index. And df.index will just be the index. So the date. Okay. So, DF index. Um, and actually, let's go ahead and we want to get rid of index column for now. We'll bring it back one of these days, but for now, we want to get rid of that. So, dfindex is not dates. I don't think it's going to handle the dates very well in Mplot Live 3D. So, DF.index. Now, that'll just be uh I think it'll probably start at 0 1 2 3 4 5 and it just goes all the way through. Might start at one. I'm not sure which one it starts with. We'll find out. Uh so, DF index, and then we're going to say DF uh we'll do H minus L and then DF close. Okay, so those are the three things. We have X, Y, and a Z now for this scatter plot that we're going to do. And then we're going to say 3D set_X label. and then make some par or uh quotes there. We're going to copy this paste. Paste x y z. Our x label is just the index. Our y label is h minus l. And then finally our z label is close. And that will should be enough. We'll find out I suppose. And so let's go ahead and save and run that. And we sure enough we get our 3D plot here. So, here we have um and just as for the record, I think the back arrow, okay, the arrows don't do anything. This pan basically does what all the clicks do. Zoom works. And oops, I didn't mean to hit save figure. And I don't know if subplots works or not. I guess we'll find out. Oh, it does. Okay, so we can do that. But basically, the arrows don't work. There's no point to this. And zoom works at least though. Now, um so if we do this, we can see. Okay, so this was the price looks like I think it starts at zero. I don't know. So this is price, right? And then what we can do though is we can um turn this a little bit, right? And we can see this is high minus low. So as the high minus low goes up, it almost looks like that mostly happens when price is low, right? Because this was the close price. So this seems to happen more often like the high minus low variance. So volatility, I suppose we could call it, seems to happen more when the close price is lower than when the close price is higher. It seems to get pretty tight as you get higher price, which is odd. You would kind of assume that high minus low is either at the extremes on either end, but looks more to me like it's kind of low. But anyway, so that's um just an example of doing some 3D plotting. Um I thought zoom worked, but it does not look like zoom works. I lied. Anyway, so there's your 3D plot. We have a lot of plots on here, so it kind of lags on my computer, and depending on what kind of computer you have, it probably lags even more. This is all plotting with your G or your CPU rather, not your GPU. If you plotted on your GPU, you'd get a lot better results. But, uh, this is CPU right here. So, anyway, we'll close out of that. Um, and so there's obviously all kinds of stuff that we could plot here. We could plot um something like this like we can have index highus low and then we could do let's say volume and then df volume here and so we could compare you know does how does the high minus low react with volume right so we have index that's just um so really we won't notice anything here but as volume goes up well volume first of all volume has gone up since the beginning interesting And then here we can compare as high minus low gets larger what does volume do or as volume gets larger what does high minus low do. So we can see that as the two of them rise kind of together because they're you can see like as this goes up it seems as though volume goes up but there are some more volume is still kind of low. Anyway, um probably no no no uh no money to be made in this kind of analysis, but just want to show you guys uh 3D plotting uh just some basic uh examples. Now, you can do all kinds of 3D plots. You can do planes, you can do bars and all that. I have tutorials on those as well. If you want to dig into more um 3D plotting, uh you can check those out. Um so anyway, that's going to conclude this video. Uh if you guys have any questions or comments, 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 video, we show that not only can we plot 2-dimensional graphs with Matplotlib and Pandas, but we can also plot three dimensional graphs with Matplot3d! Here, we show a few examples, like Price, to date, to H-L, for example. There are many other things we can compare, and 3D Matplotlib is not limited to scatter plots. We can do wire frames, bars, and more as well! Sample code for the series: http://pythonprogramming.net/python-2-7-pandas-data-analysis/ Pandas tutorial series: https://www.youtube.com/playlist?list=PLQVvvaa0QuDfHt4XU7vTm22xDegR0v0fQ 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 how to create 3D graphs using Matplotlib and Pandas in Python 2.7, covering the basics of 3D plotting and data visualization.

Key Takeaways
  1. Import necessary libraries (Matplotlib, Pandas, mpl_toolkits)
  2. Create a 3D figure using plt.figure()
  3. Make a scatter plot using 3D.scatter()
  4. Set x, y, and z labels using 3D.set_xlabel(), 3D.set_ylabel(), and 3D.set_zlabel()
💡 3D plotting can be used to visualize complex data relationships, such as the relationship between price, high minus low, and volume.

Related Reads

Up next
how i use a.i. to create viral UGC influencer facebook ads.
Austin Rabin
Watch →