0
0
Matplotlibdata~30 mins

Why 3D visualization matters in Matplotlib - See It in Action

Choose your learning style9 modes available
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
Need a 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
Need a 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
Need a 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
Need a hint?

Use plt.show() to open the window with the 3D plot.