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

วิธีปิด Error Bars ใน Seaborn Bar Plot ด้วย Matplotlib


ภาพรวม

Seaborn barplot() แสดง Error Bars (Confidence Intervals) โดย Default สามารถปิดได้ด้วย ci=None

ขั้นตอน

  1. โหลด Dataset ตัวอย่าง (Titanic)
  2. พลอต Barplot ด้วย ci=None
  3. แสดงผล

ตัวอย่างโค้ด

import seaborn as sns
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

df = sns.load_dataset('titanic')
sns.barplot(x='class', y='age', hue='survived', data=df, ci=None)
plt.show()

ผลลัพธ์

Bar Chart แสดงอายุเฉลี่ยตาม Class และ Survived ไม่มี Error Bars

พารามิเตอร์ ci อื่นๆ

  • ci=95 (Default): 95% Confidence Interval
  • ci='sd': Standard Deviation
  • ci=None: ปิด Error Bars
  • ci=68: 68% CI (1 Sigma)