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

วิธีใช้ Seaborn แสดง Categorical Scatter Plots ใน Python

Seaborn visualize ข้อมูล มี theme และ high-level interface scatter plot, histogram ทั่วไปไม่เหมาะกับ categorical variables ต้องใช้ categorical scatterplots: 'stripplot', 'swarmplot'

'stripplot' ใช้เมื่อตัวแปรอย่างน้อยหนึ่งตัวเป็น categorical ข้อมูลเรียงตามแกนหนึ่ง

Syntax stripplot

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

ตัวอย่าง

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

ผลลัพธ์

วิธีใช้ Seaborn แสดง Categorical Scatter Plots ใน Python

คำอธิบาย

  • นำเข้าแพ็กเกจ
  • โหลดข้อมูล 'iris' จาก seaborn (ไม่ใช่ scikit-learn)
  • เก็บใน DataFrame
  • ใช้ 'stripplot' visualize
  • ระบุ dataframe, x, y
  • อาจมีจุดทับซ้อนกัน
  • แสดงผล

stripplot อาจมี overplotting แก้ด้วย jitter หรือใช้ swarmplot แทน