Bar Plot ใน Seaborn ใช้เพื่อแสดงค่าประมาณจุดและช่วงความเชื่อมั่นเป็นแท่งสี่เหลี่ยม ใช้ seaborn.barplot() ตั้งค่าตัวพิมพ์ใหญ่เป็นแถบข้อผิดพลาดโดยใช้ พลิก พารามิเตอร์
สมมติว่าต่อไปนี้คือชุดข้อมูลของเราในรูปแบบไฟล์ CSV - Cricketers2.csv
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import seaborn as sb import pandas as pd import matplotlib.pyplot as plt
โหลดข้อมูลจากไฟล์ CSV ลงใน Pandas DataFrame -
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers2.csv")
ตั้งค่าตัวพิมพ์ใหญ่เป็นแถบข้อผิดพลาดโดยใช้ พลิก พารามิเตอร์ -
sb.barplot(x=dataFrame["Role"], y=dataFrame["Matches"], capsize=.3)
ตัวอย่าง
ต่อไปนี้เป็นรหัส -
import seaborn as sb
import pandas as pd
import matplotlib.pyplot as plt
# Load data from a CSV file into a Pandas DataFrame
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers2.csv")
sb.set_theme(style="darkgrid")
# bar plot
# setting caps to the error bars using the capsize parameter
sb.barplot(x=dataFrame["Role"], y=dataFrame["Matches"], capsize=.3)
# display
plt.show() ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
