โครงเรื่องไวโอลินใน Seaborn ใช้เพื่อวาดชุดค่าผสมของ boxplot และค่าความหนาแน่นของเคอร์เนล ใช้ seaborn.violinplot() ตั้งค่าควอไทล์เป็นเส้นแนวนอนโดยใช้ ด้านใน พารามิเตอร์ที่มีค่า ควอร์ไทล์ .
สมมติว่าต่อไปนี้คือชุดข้อมูลของเราในรูปแบบไฟล์ CSV −Cricketers.csv
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import seaborn as sb import pandas as pd import matplotlib.pyplot as plt
โหลดข้อมูลจากไฟล์ CSV ลงใน Pandas DataFrame -
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers.csv") พล็อตเรื่องไวโอลินกับบทบาทและอายุ ลำดับของกล่องควบคุมโดยการส่งคำสั่งที่ชัดเจน เช่น การสั่งซื้อตาม "บทบาท" ตั้งค่าควอไทล์เป็นเส้นแนวนอนโดยใช้พารามิเตอร์ภายในที่มีค่าควอไทล์ -
sb.violinplot(x = 'Role', y = "Age", order=["Batsman", "Bowler"], data = dataFrame, inner="quartile")
ตัวอย่าง
ต่อไปนี้เป็นรหัส
import seaborn as sb
import pandas as pd
import matplotlib.pyplot as plt
# Load data from a CSV file into a Pandas DataFrame:
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers.csv")
# plotting violin plot with Role and Age
# Control box order by passing an explicit order i.e. ordering on the basis of "Role"
# quartiles as horizontal lines using the inner parameter with value quartile
sb.violinplot(x = 'Role', y = "Age", order=["Batsman", "Bowler"], data = dataFrame, inner="quartile")
# display
plt.show()
ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้
