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

วิธีใช้ Box และ Whisker Plot เปรียบเทียบข้อมูลใน Seaborn Python

Seaborn visualize ข้อมูล Scatter plot ให้ข้อมูลจำกัด (แค่ distribution ใน category) ต้องการเปรียบเทียบข้าม categories ใช้ box plot เข้าใจการกระจายด้วย quartiles มี whiskers แสดงการกระจายนอก upper/lower quartiles เรียกว่า whisker plot outliers = จุดเดี่ยว

Syntax boxplot

seaborn.boxplot(x, y, data, ...)

ตัวอย่าง

import pandas as pd
import seaborn as sb
from matplotlib import pyplot as plt
my_df = sb.load_dataset('iris')
sb.boxplot(x="species", y="petal_length", data=my_df)
plt.show()

ผลลัพธ์

วิธีใช้ Box และ Whisker Plot เปรียบเทียบข้อมูลใน Seaborn Python

คำอธิบาย

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

Box plot แสดง median, Q1, Q3, whiskers (1.5*IQR), outliers ช่วยเปรียบเทียบ distribution ระหว่าง species