3D Graphs in Matplotlib for Python: Basic 3D Line

sentdex · Beginner ·💻 AI-Assisted Coding ·12y ago
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 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
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

Related AI Lessons

Vibe Coding Problems: What AI-Generated Code Gets Wrong
Learn how AI-generated code can fail in production despite working in demos, and what red flags to look out for in codebases
Dev.to AI
I Almost Quit Java After My First Project (Then One Bug Changed Everything)
A Java developer shares how overcoming a single bug transformed their approach to coding and problem-solving, highlighting the importance of learning how real developers think
Medium · Programming
The Rise of Vibe Coding: Are Traditional Programming Languages Dead?
Explore the emergence of vibe coding and its potential impact on traditional programming languages
Medium · Programming
Vibe Computing: The Moment We Stop Operating Computers
Learn about Vibe Computing, a new paradigm where computers adapt to human behavior, making interactions more intuitive and natural
Medium · Data Science
Up next
Azure Security Priorities for 2026: Identity, Governance, AI Security & Zero Trust
Valto Microsoft Specialists
Watch →