Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Why 3D visualization matters
📖 Scenario: Imagine you work in a company that studies how different factors affect sales. You have data with three features: advertising budget, price, and sales. You want to understand how these three things relate to each other. A 3D plot can help you see the relationship clearly.
🎯 Goal: You will create a simple 3D scatter plot using matplotlib to visualize how advertising budget and price relate to sales. This will show why 3D visualization matters when you have three variables.
📋 What You'll Learn
Create three lists named advertising, price, and sales with exact values
Create a variable fig for the figure and ax for 3D axes using matplotlib
Plot a 3D scatter plot using ax.scatter with the three lists
Label the axes with ax.set_xlabel, ax.set_ylabel, and ax.set_zlabel
Show the plot using plt.show()
💡 Why This Matters
🌍 Real World
3D visualization helps businesses and scientists see how three factors relate, like how advertising and price affect sales together.
💼 Career
Data scientists and analysts use 3D plots to explore and explain data with three variables, making insights clearer for decision makers.
Progress0 / 4 steps
1
Create the data lists
Create three lists called advertising, price, and sales with these exact values: advertising = [100, 200, 300, 400, 500] price = [10, 9, 8, 7, 6] sales = [20, 40, 60, 80, 100]
Matplotlib
Hint
Use square brackets to create lists. Separate numbers with commas.
2
Set up the 3D plot
Import matplotlib.pyplot as plt and import Axes3D from mpl_toolkits.mplot3d. Then create a figure called fig using plt.figure() and create 3D axes called ax using fig.add_subplot(111, projection='3d').
Matplotlib
Hint
Use import matplotlib.pyplot as plt and from mpl_toolkits.mplot3d import Axes3D. Then create the figure and 3D axes as shown.
3
Plot the 3D scatter plot
Use ax.scatter to plot the points with advertising on the x-axis, price on the y-axis, and sales on the z-axis. Then label the axes with ax.set_xlabel('Advertising Budget'), ax.set_ylabel('Price'), and ax.set_zlabel('Sales').
Matplotlib
Hint
Use ax.scatter(x, y, z) to plot points in 3D. Then label each axis with ax.set_xlabel, ax.set_ylabel, and ax.set_zlabel.
4
Show the 3D plot
Use plt.show() to display the 3D scatter plot.
Matplotlib
Hint
Use plt.show() to open the window with the 3D plot.
Practice
(1/5)
1. Why is 3D visualization important in data science?
easy
A. It helps show relationships among three variables clearly.
B. It makes data smaller and easier to store.
C. It removes the need for data cleaning.
D. It automatically finds patterns without analysis.
Solution
Step 1: Understand the role of 3D visualization
3D visualization is used to display data with three variables or dimensions.
Step 2: Identify the benefit of 3D plots
It helps reveal complex relationships that are hard to see in 2D plots.
Final Answer:
It helps show relationships among three variables clearly. -> Option A
Quick Check:
3D plots = show 3-variable relationships [OK]
Hint: 3D plots show three variables' relationships clearly [OK]
Common Mistakes:
Thinking 3D plots reduce data size
Believing 3D plots clean data automatically
Assuming 3D plots find patterns without analysis
2. Which of the following is the correct way to import 3D plotting tools from matplotlib?
easy
A. import matplotlib3d as plt; from mpl_toolkits import Axes3D
B. from matplotlib import pyplot as plt; from mpl_toolkits.mplot3d import Axes3D
C. from matplotlib import Axes3D; import pyplot as plt
D. import matplotlib.pyplot as plt; import mpl_toolkits.mplot3d.Axes3D
Solution
Step 1: Recall correct import syntax for 3D plotting
The standard way is to import pyplot as plt and import Axes3D from mpl_toolkits.mplot3d.
Step 2: Check each option for syntax correctness
from matplotlib import pyplot as plt; from mpl_toolkits.mplot3d import Axes3D matches the correct syntax; others have wrong import statements or missing parts.
Final Answer:
from matplotlib import pyplot as plt; from mpl_toolkits.mplot3d import Axes3D -> Option B
Quick Check:
Correct 3D import = from matplotlib import pyplot as plt; from mpl_toolkits.mplot3d import Axes3D [OK]
Hint: Use 'from mpl_toolkits.mplot3d import Axes3D' for 3D plots [OK]
Common Mistakes:
Using incorrect import paths
Trying to import Axes3D directly from matplotlib
Mixing import styles incorrectly
3. What will the following code output?
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter([1,2], [3,4], [5,6])
plt.show()
medium
A. Empty plot with no points shown
B. A 2D scatter plot ignoring the z values
C. SyntaxError due to wrong subplot code
D. A 3D scatter plot with points at (1,3,5) and (2,4,6)
Solution
Step 1: Analyze the code for 3D scatter plot creation
The code creates a 3D subplot and plots points at given x, y, z coordinates.
Step 2: Understand the scatter method with 3D data
ax.scatter plots points in 3D space at (1,3,5) and (2,4,6).
Final Answer:
A 3D scatter plot with points at (1,3,5) and (2,4,6) -> Option D
Quick Check:
3D scatter shows given points [OK]
Hint: ax.scatter with projection='3d' plots 3D points [OK]