แนะนำ Relational Plots และ Subplots

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

Content Team

DataCamp

คำถามเกี่ยวกับตัวแปรเชิงปริมาณ

Relational plots

  • ส่วนสูง vs. น้ำหนัก

Scatter plot ของส่วนสูงเทียบกับน้ำหนัก

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

คำถามเกี่ยวกับตัวแปรเชิงปริมาณ

Relational plots

  • ส่วนสูง vs. น้ำหนัก
  • จำนวนวันขาดเรียน vs. เกรดสุดท้าย

Scatter plot ของจำนวนวันขาดเรียนเทียบกับเกรดสุดท้าย

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

คำถามเกี่ยวกับตัวแปรเชิงปริมาณ

Relational plots

  • ส่วนสูง vs. น้ำหนัก
  • จำนวนวันขาดเรียน vs. เกรดสุดท้าย
  • GDP vs. อัตราการรู้หนังสือ

Scatter plot ของ GDP เทียบกับอัตราการรู้หนังสือ

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

Scatter plot ที่ใช้ hue แยกกลุ่ม

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

Scatter plot ที่แบ่งเป็น subplots

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

แนะนำ relplot()

  • สร้าง "relational plots": scatter plot หรือ line plot

ทำไมต้องใช้ relplot() แทน scatterplot()?

  • relplot() ช่วยให้สร้าง subplots หลายแผนภูมิในรูปเดียวได้
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

scatterplot() vs. relplot()

การใช้ scatterplot()

import seaborn as sns
import matplotlib.pyplot as plt

sns.scatterplot(x="total_bill", 
                y="tip", 
                data=tips)

plt.show()

การใช้ relplot()

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter")

plt.show()
1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

Subplots ตามคอลัมน์

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="smoker")

plt.show()

Scatter plot ที่แบ่ง subplots ตามคอลัมน์สำหรับผู้สูบบุหรี่

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

Subplots ตามแถว

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            row="smoker")

plt.show()

Scatter plot ที่แบ่ง subplots ตามแถวสำหรับผู้สูบบุหรี่

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

Subplots ตามแถวและคอลัมน์

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="smoker",
            row="time")

plt.show()

Scatter plot ที่แบ่ง subplots ตามผู้สูบบุหรี่และเวลา

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

กลุ่มย่อยตามวันในสัปดาห์

Scatter plot ที่แบ่ง subplots ตามวันในคอลัมน์

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

การตัดคอลัมน์ขึ้นแถวใหม่

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="day",
            col_wrap=2)

plt.show()

Scatter plot ที่แบ่ง subplots ตามวันเป็นสองแถว

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

การเรียงลำดับคอลัมน์

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="day",
            col_wrap=2,
            col_order=["Thur",
                       "Fri",
                       "Sat",
                       "Sun"])

plt.show()

Scatter plot ที่แบ่ง subplots ตามวันแบบเรียงลำดับ

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
การสร้างภาพข้อมูลด้วย Seaborn เบื้องต้น

มาฝึกกันเถอะ!

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

Preparing Video For Download...