3D Graphs in Matplotlib for Python: Basic 3D Line
Skills:
AI Pair Programming80%
Once you get comfortable with the 2D graphing, you might be interested in learning how to plot three-dimensional charts. 3D graphs add more perspective and comparison to your charts, and just plain look cool! Luckily for us, 3D graphs are pretty easy to learn and program with Matplotlib.
Here is some quick and simple, with hard-coded values, for a 3-D matplotlib wire chart.
Link to the full playlist:
http://www.youtube.com/playlist?list=PLQVvvaa0QuDfpEcGUM6ogsbrlWtqpS5-1
Sample code: http://pythonprogramming.net/3d-graphing-python-matplotlib/
Sentdex.com
Facebook.com/sentdex
Twitter.com/sentdex
How to make a basic 3D line graph with Matplotlib in python
What You'll Learn
Creates a basic 3D line graph using Matplotlib in Python
Full Transcript
hello everybody and welcome to the continuation of the matplot lib Series in this video in the next few subsequent videos we're going to be talking about 3D plotting so pretty exciting stuff so with that let's go ahead and hop in and get right to it so first thing that we're going to need uh that you'll notice is a little bit different is from noore toolkit. and plot 3D we want to import axis 3D so um basically so we can start to use that axis 3D framework the next thing we need is import M plot li. pyplot as uh PLT so that's not new so the next thing we want to do is we want to um Define our figure so this is also nothing new it's just going to be big equals plot. figure uh the next thing we want to do is Define the axes um so we're going to say axal fig. addore subplot and so far that's not new and same thing with subplot those same rules apply this is 111 now what will be new is you're going to have this uh new parameter called projection and projection is um our way of telling Matt plot lib that we want to have this be a three-dimensional projection so as it's creating the axes in this subplot it's doing so with a three-dimensional uh object in mind so now the next thing that we want to do is we want to specify the plots that we want to make so uh in this case we were we're going to need uh three right we've got an x a y and a z and XYZ is going to be equal to um the plots for three different arrays so that's going to be array 1 2 3 so this will be the X plots the Y plots and the Z plots and they have to obviously equal the same right you need 10 X's 10 y's 10 Z's and so on so we're going to use um just 1 2 3 4 five 6 7 8 9 10 for the X um you can make up whatever plots you want by the way I'm just going to make some random ones real quick so you should do the same thing you won't have to copy me or anything uh 4 One 2 and then this one will be two 11 9 and 10 so I think 1 2 3 4 5 6 7 8 n 10 yeah I think we've got 10 now we'll find out uh probably an easy way to do it would just be to well never mind anyway so to find your XYZ we'll know if it doesn't plot if we did it wrong so now we do ax. plot and so that's not anything new but now you do plot underscore wireframe cuz that's what we're plotting is this wire frame and then in here you put what you want to plot in our case we want to plot XYZ and then finally you end with a plot. show and that is really it so let's generate it hopefully we don't have any typos let's see what do we do yeah okay we did we somewhere we've got an incompatible Dimension would probably be this one since we count the other ones 1 2 3 4 5 6 7 8 9 so we'll just add 10 okay save and we'll display this now it's getting angry it's angry at me at least mine does gets really angry at me whenever I uh fail at displaying the chart so anyways uh here is our chart as you might find out immediately you can begin playing with the chart by left clicking and dragging that will rotate the chart around and you can mess with it um however you can't cannot use the home button you can't so like if we do this and you hit home it's not really doing anything for us um you also can't use back and forward to previous views because it's constantly being rendered basically and I don't think it's recalling where it is like this is still the same thing that it's showing us anyway you won't be able to use those you could use this thing it doesn't do anything actually though same thing zoom zoom doesn't do anything either so you might be asking asking well how do you zoom then cuz what if you really do want to zoom um well to zoom you'll actually use your right Mouse button so just right click and hold and you can zoom in and out and then you know so you can zoom out and then continue playing with it a little bit looking around and that kind of stuff um and the other thing that will work as well if you'll notice um we not only have these spaces here on the chart the chart itself not on this side so much because the numbers are there and I the reason that spacing is there is because the numbers can flip-flop right you can have numbers on either side but it's a waste on whatever side there are no numbers so say you wanted to you know render this into an image or something then you might want to adjust with these this little adjuster thing you know that you're should be used used to by now and at least get rid of you know like the top and the right maybe and then we'll go ahead and get rid of the left and then even the bottom and this rendering we could get rid of so now you know it would be like a full-sized image and really this one you know asides from these going over that's why they made the spacing there mostly is cuz I guess it'll go over but anyway um that's that that's those are these charts uh or at least the beginning of the 3D charts there's all kinds of charts that we can do you can do bar charts either like flat bar charts or thick bar charts you can make it look like a city in here basically Scatter Plots um which is useful for machine learning for sure especially with the third dimension um and and some other stuff especially like the planes people really like to see like planes like probably this most stereotypical 3D plot that you can think of so anyway with that that's going to conclude this basic tutorial we will be continuing on with some more um of the 3D plotting tutorials that's for sure I just wanted to put this one out uh before people started to Mutiny over my WordPress tutorial and I wasn't putting anything else fancy out so anyway that's the first 3D plot and as always thank you for watching thanks for your support your subscriptions and until next time
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 46 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
▶
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: AI Pair Programming
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Vibe Coding Problems: What AI-Generated Code Gets Wrong
Dev.to AI
I Almost Quit Java After My First Project (Then One Bug Changed Everything)
Medium · Programming
The Rise of Vibe Coding: Are Traditional Programming Languages Dead?
Medium · Programming
Vibe Computing: The Moment We Stop Operating Computers
Medium · Data Science
🎓
Tutor Explanation
DeepCamp AI