Create a Height vs Weight Scatter Plot
Intermediate · Write the code · from Matplotlib: Create Line, Bar, Scatter, and Pie Charts
From the lesson: Matplotlib: Create Line, Bar, Scatter, and Pie Charts
Imagine you have a spreadsheet with 10,000 rows of sales data. You could stare at those numbers for hours, or you could turn them into a chart and spot the trend in three seconds. That's the power of data visualization.
Read the lessonCreate a scatter plot of height vs weight data. Use ax.scatter() with alpha=0.6. Set the title to 'Height vs Weight'. Print the number of data points in the scatter collection using len(ax.collections[0].get_offsets()).
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
heights = [160, 165, 170, 175, 180, 185, 170, 168, 172, 178]
weights = [55, 62, 68, 74, 80, 85, 65, 60, 70, 76]
# Create scatter plot with alpha=0.6
# Set title
# Print number of data points
More Matplotlib exercises
- Build a Temperature Line ChartIntermediate
- Build a Fruit Sales Bar ChartIntermediate
- Predict the Figure PropertiesIntermediate
- Fix the Broken LegendIntermediate
- Prepare Data for a Multi-Series ChartIntermediate
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz