Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

Python Pandas - วาด Bar Plot และตั้งค่า Cap ให้ Error Bars ด้วย Seaborn

บทนำ

Bar Plot ใน Seaborn แสดงประมาณค่าจุดและช่วงเชื่อมั่นเป็นแท่งสี่เหลี่ยม ใช้ seaborn.barplot() ตั้งค่า Cap ให้ Error Bars ด้วยพารามิเตอร์ capsize

ขั้นตอน

  1. นำเข้าไลบรารี
  2. โหลดข้อมูลจาก Cricketers2.csv
  3. วาด Bar Plot พร้อมตั้งค่า capsize=.3:
    sb.barplot(x=dataFrame["Role"], y=dataFrame["Matches"], capsize=.3)

โค้ดเต็ม

import seaborn as sb
import pandas as pd
import matplotlib.pyplot as plt

dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers2.csv")
sb.set_theme(style="darkgrid")

# Bar Plot พร้อม Cap บน Error Bars
sb.barplot(x=dataFrame["Role"], y=dataFrame["Matches"], capsize=.3)
plt.show()

ผลลัพธ์

ได้ Bar Plot แสดงจำนวนแมตช์เฉลี่ยแยกตาม Role พร้อม Error Bars ที่มี Cap