Menyiapkan figur untuk dibagikan

Pengantar Visualisasi Data dengan Matplotlib

Ariel Rokem

Data Scientist

Mengubah gaya plot

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("Waktu (bulan)")
ax.set_ylabel("Suhu rata-rata (derajat Fahrenheit)")
plt.show()

Pengantar Visualisasi Data dengan Matplotlib

Memilih gaya

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("Waktu (bulan)") ax.set_ylabel("Suhu rata-rata (derajat Fahrenheit)") plt.show()

Pengantar Visualisasi Data dengan Matplotlib

Kembali ke default

plt.style.use("default")
Pengantar Visualisasi Data dengan Matplotlib

Gaya yang tersedia

Pengantar Visualisasi Data dengan Matplotlib

Gaya "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("Waktu (bulan)") ax.set_ylabel("Suhu rata-rata (derajat Fahrenheit)") plt.show()

Pengantar Visualisasi Data dengan Matplotlib

Gaya 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("Waktu (bulan)") ax.set_ylabel("Suhu rata-rata (derajat Fahrenheit)") plt.show()

Pengantar Visualisasi Data dengan Matplotlib

Panduan memilih gaya plot

  • Latar gelap biasanya kurang jelas
  • Jika warna penting, pilih opsi ramah buta warna
    • "seaborn-colorblind" atau "tableau-colorblind10"
  • Jika figur mungkin dicetak, hemat tinta
  • Jika dicetak hitam-putih, gunakan gaya "grayscale"
Pengantar Visualisasi Data dengan Matplotlib

Ayo berlatih!

Pengantar Visualisasi Data dengan Matplotlib

Preparing Video For Download...