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

Python Pandas - วาดพล็อตจุดและควบคุมลำดับโดยส่งคำสั่งที่ชัดเจนกับ Seaborn


Point Plot ใน Seaborn ใช้เพื่อแสดงค่าประมาณจุดและช่วงความเชื่อมั่นโดยใช้ร่ายมนตร์พล็อตแบบกระจาย seaborn.pointplot() ใช้สำหรับสิ่งนี้ สำหรับคำสั่งที่ชัดเจน ให้ใช้คำสั่ง พารามิเตอร์ของเมธอด pointplot()

สมมติว่าต่อไปนี้คือชุดข้อมูลของเราในรูปแบบไฟล์ 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")

พล็อตจุดพล็อตด้วย "Academy" และ "Age" ควบคุมคำสั่งโดยส่งคำสั่งที่ชัดเจนเช่น การสั่งซื้อบนพื้นฐานของ "สถาบันการศึกษา" การสั่งซื้อโดยใช้พารามิเตอร์การสั่งซื้อ -

sb.pointplot( x = 'Academy',y = 'Age', data = dataFrame, order=["Tasmania", "South Australia", "Victoria"] )

ตัวอย่าง

ต่อไปนี้เป็นรหัสที่สมบูรณ์ -

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")

sb.set_theme(style="darkgrid")

# plotting point plot with Academy and Age
# Control order by passing an explicit order i.e. ordering on the basis of "Academy"
# ordering using the order parameter
sb.pointplot( x = 'Academy',y = 'Age', data = dataFrame, order=["Tasmania", "South Australia", "Victoria"] )

# display
plt.show()

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

Python Pandas - วาดพล็อตจุดและควบคุมลำดับโดยส่งคำสั่งที่ชัดเจนกับ Seaborn