Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Python Pandas - Vẽ biểu đồ cột (bar plot) và đặt mũi tên cho thanh lỗi (error bars) với Seaborn


Bar Plot trong Seaborn hiển thị ước lượng điểm và khoảng tin cậy bằng các cột chữ nhật. Hàm seaborn.barplot() được sử dụng. Đặt mũi tên (caps) cho thanh lỗi bằng tham số capsize.

Tập dữ liệu: Cricketers2.csv.

Nhập thư viện:

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

Tải dữ liệu:

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

Đặt mũi tên cho thanh lỗi bằng tham số capsize:

sb.barplot(x=dataFrame["Role"], y=dataFrame["Matches"], capsize=.3)

Ví dụ

import seaborn as sb 
import pandas as pd 
import matplotlib.pyplot as plt 
# Tải dữ liệu 
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers2.csv") 
sb.set_theme(style="darkgrid") 
# Bar plot với mũi tên thanh lỗi 
sb.barplot(x=dataFrame["Role"], y=dataFrame["Matches"], capsize=.3) 
plt.show()

Kết quả

Python Pandas - Vẽ biểu đồ cột (bar plot) và đặt mũi tên cho thanh lỗi (error bars) với Seaborn