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

หลีกเลี่ยงจุดทับซ้อนใน Categorical Scatter Plot โดยไม่ใช้ jitter ใน Seaborn Python

Seaborn visualize ข้อมูล stripplot: ตัวแปรอย่างน้อย 1 ตัวเป็น categorical ข้อมูลเรียงตามแกน แต่จุดอาจทับซ้อน ใช้ 'jitter' parameter เพิ่ม noise ปรับตำแหน่ง แต่สามารถใช้ 'swarmplot' แทนได้

Syntax swarmplot

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

ตัวอย่าง

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

ผลลัพธ์

หลีกเลี่ยงจุดทับซ้อนใน Categorical Scatter Plot โดยไม่ใช้ jitter ใน Seaborn Python

คำอธิบาย

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

Swarmplot จัดจุดไม่ให้ทับซ้อนโดยปรับตำแหน่งบน categorical axis แสดงการกระจายจริงกว่า stripplot+jitter