Vẽ biểu đồ các phép nội suy
Vẽ các biểu đồ so sánh cho việc bù dữ liệu là bước quan trọng để suy ra kỹ thuật bù tốt nhất. Trong bài này, bạn sẽ tạo một vòng lặp for để sinh các biểu đồ cho nhiều kỹ thuật bù. Bạn sẽ vẽ các biểu đồ cho những phép bù đã thực hiện ở bài trước, tức là các kỹ thuật nội suy tuyến tính (linear), bậc hai (quadratic), và láng giềng gần nhất (nearest).
Ba DataFrame được đặt tên theo kỹ thuật bù đã được nhập sẵn cho bạn, gồm linear_interp, quadratic_interp, và nearest_interp.
Bài tập này là một phần của khóa học
Xử lý Dữ liệu Khuyết trong Python
Hướng dẫn bài tập
- Tạo 3 biểu đồ con (subplots) cho mỗi kỹ thuật bù.
- Tạo từ điển
interpolationsbằng cách ánh xạ các DataFramelinear_interp,quadratic_interp, vànearest_interptới kỹ thuật nội suy tương ứng. - Lặp qua
axesvàinterpolations. - Chọn từng DataFrame trong
interpolationsvà đặt tiêu đề cho DataFrame đó bằngdf_key.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
# Set nrows to 3 and ncols to 1
fig, axes = plt.subplots(___, ___, figsize=(30, 20))
# Create a dictionary of interpolated DataFrames for looping
interpolations = {'Linear Interpolation': ___, 'Quadratic Interpolation': ___,
'Nearest Interpolation': ___}
# Loop over axes and interpolations
for ax, df_key in zip(___, ___):
# Select and also set the title for a DataFrame
interpolations[___].Ozone.plot(color='red', marker='o', linestyle='dotted', ax=ax)
airquality.Ozone.plot(title=___ + ' - Ozone', marker='o', ax=ax)
plt.show()