Editor

Predict the Figure Properties

Intermediate · Predict the output · 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 lesson

What will this code print? Think about figure dimensions and line count.

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(12, 8))
ax.plot([1, 2, 3], [10, 20, 30], label='A')
ax.plot([1, 2, 3], [30, 20, 10], label='B')
ax.set_title('Two Lines')
print(fig.get_size_inches()[0])
print(len(ax.lines))

More Matplotlib exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz