การสร้าง Barplot ทีละขั้น

Python สำหรับผู้ใช้สเปรดชีต

Chris Cardillo

Data Scientist

Barplot เดิม

sns.barplot(x='store', y='revenue', data=totals)

plt.show()

store totals plot only.png

Python สำหรับผู้ใช้สเปรดชีต

การเพิ่ม Label

sns.barplot(x='store', 
            y='revenue', 
            data=totals)

# Add a title

# Add x-axis label

# Add y-axis label

plt.show()

store totals plot only.png

Python สำหรับผู้ใช้สเปรดชีต

เพิ่มชื่อกราฟด้วย plt.title()

sns.barplot(x='store', 
            y='revenue', 
            data=totals)

plt.title('Revenue by Store')

# Add x-axis label

# Add y-axis label

plt.show()

กราฟ Revenue by Store พร้อมชื่อ

Python สำหรับผู้ใช้สเปรดชีต

เพิ่ม Label แกน x ด้วย plt.xlabel()

sns.barplot(x='store', 
            y='revenue', 
            data=totals)

plt.title('Revenue by Store')

plt.xlabel('Store')

# Add y-axis label

plt.show()

กราฟ Revenue by Store พร้อมชื่อและ label แกน x

Python สำหรับผู้ใช้สเปรดชีต

เพิ่ม Label แกน y ด้วย plt.ylabel()

sns.barplot(x='store', 
            y='revenue', 
            data=totals)

plt.title('Revenue by Store')

plt.xlabel('Store')

plt.ylabel('Revenue (USD)')

plt.show()

กราฟ Revenue by Store พร้อม Label ครบทุกแกน

Python สำหรับผู้ใช้สเปรดชีต

ลบเส้นขอบที่ไม่ต้องการด้วย sns.despine()

sns.barplot(x='store', 
            y='revenue', 
            data=totals)

plt.title('Revenue by Store')

plt.xlabel('Store')

plt.ylabel('Revenue (USD)')

sns.despine()

plt.show()

กราฟ Revenue by Store ที่ลบขอบออกแล้ว

Python สำหรับผู้ใช้สเปรดชีต

ปรับสไตล์ด้วย sns.set_style()

sns.set_style('whitegrid')

sns.barplot(x='store', 
            y='revenue', 
            data=totals)

plt.title('Revenue by Store')

plt.xlabel('Store')

plt.ylabel('Revenue (USD)')

sns.despine()

plt.show()

กราฟ Revenue by Store เวอร์ชันสมบูรณ์

Python สำหรับผู้ใช้สเปรดชีต

เปรียบเทียบก่อนและหลัง

ก่อน

store totals plot only.png

หลัง

กราฟ Revenue by Store เวอร์ชันสมบูรณ์

Python สำหรับผู้ใช้สเปรดชีต

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

Python สำหรับผู้ใช้สเปรดชีต

Preparing Video For Download...