Chuẩn bị biểu đồ để chia sẻ

Nhập môn trực quan hóa dữ liệu với Matplotlib

Ariel Rokem

Data Scientist

Thay đổi kiểu biểu đồ

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"])
ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"])
ax.set_xlabel("Time (months)")
ax.set_ylabel("Average temperature (Fahrenheit degrees)")
plt.show()

Nhập môn trực quan hóa dữ liệu với Matplotlib

Chọn một kiểu

plt.style.use("ggplot")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Nhập môn trực quan hóa dữ liệu với Matplotlib

Quay lại mặc định

plt.style.use("default")
Nhập môn trực quan hóa dữ liệu với Matplotlib

Các kiểu có sẵn

Nhập môn trực quan hóa dữ liệu với Matplotlib

Kiểu "bmh"

plt.style.use("bmh")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Nhập môn trực quan hóa dữ liệu với Matplotlib

Các kiểu Seaborn

plt.style.use("seaborn-colorblind")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Nhập môn trực quan hóa dữ liệu với Matplotlib

Hướng dẫn chọn kiểu vẽ

  • Nền tối thường kém rõ ràng hơn
  • Nếu màu quan trọng, hãy chọn bảng thân thiện với người mù màu
    • "seaborn-colorblind" hoặc "tableau-colorblind10"
  • Nếu người xem có thể in biểu đồ, hãy giảm lượng mực
  • Nếu in đen–trắng, dùng kiểu "grayscale"
Nhập môn trực quan hóa dữ liệu với Matplotlib

Luyện chọn kiểu phù hợp!

Nhập môn trực quan hóa dữ liệu với Matplotlib

Preparing Video For Download...