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

วิธีใช้ Bar Plot ใน Seaborn Library Python

Seaborn visualize ข้อมูล barplot: categorical vs continuous แสดงความสัมพันธ์ ข้อมูลเป็นแท่งสี่เหลี่ยม ความยาว = สัดส่วนข้อมูลใน category นั้น

ตัวอย่าง

import pandas as pd
import seaborn as sb
from matplotlib import pyplot as plt
my_df = sb.load_dataset('titanic')
sb.barplot(x="sex", y="survived", hue="class", data=my_df)
plt.show()

ผลลัพธ์

วิธีใช้ Bar Plot ใน Seaborn Library Python

คำอธิบาย

  • นำเข้าแพ็กเกจ
  • โหลดข้อมูล 'titanic' จาก seaborn
  • เก็บใน DataFrame
  • ใช้ 'barplot' visualize
  • ระบุ dataframe, x, y, hue
  • แสดงผล

Barplot แสดงค่าเฉลี่ย (mean) ของ y ในแต่ละ x category พร้อม confidence interval (bootstrapped)