การเตรียมกราฟเพื่อแชร์ให้ผู้อื่น

การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น

Ariel Rokem

Data Scientist

การเปลี่ยนสไตล์กราฟ

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()

การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น

การเลือกสไตล์

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()

การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น

กลับสู่สไตล์เริ่มต้น

plt.style.use("default")
การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น

สไตล์ที่มีให้เลือกใช้

การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น

สไตล์ "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()

การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น

สไตล์ 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()

การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น

แนวทางการเลือกสไตล์กราฟ

  • พื้นหลังสีเข้มมักมองเห็นได้ยากกว่า
  • หากสีมีความสำคัญ ควรเลือกสไตล์ที่เป็นมิตรกับผู้บกพร่องทางสี
    • "seaborn-colorblind" หรือ "tableau-colorblind10"
  • หากคาดว่าจะมีการพิมพ์กราฟ ควรใช้สีให้น้อยลง
  • หากจะพิมพ์ขาวดำ ให้ใช้สไตล์ "grayscale"
การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น

มาฝึกเลือกสไตล์ที่เหมาะกับคุณกันเถอะ!

การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น

Preparing Video For Download...