在條形圖中指示統計顯著性差異 (Matplotlib)


為了在條形圖中指示統計顯著性差異,我們可以採取以下步驟:

  • 設定圖形大小並調整子圖之間和周圍的填充。
  • 建立**均值**、**標準差**、**索引**、**寬度**和**標籤**資料點。
  • 使用**subplots()**方法建立一個圖形和一組子圖。
  • 使用**bar()**方法制作條形圖。
  • 使用附加誤差線的線和/或標記繪製Y與X的關係。縮放Y軸。
  • 獲取或設定X軸的當前刻度位置和標籤。
  • 要顯示圖形,請使用**show()**方法。

示例

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

means = (5, 15, 30, 40)
std = (2, 3, 4, 5)
index = np.arange(4)
width = 0.7
labels = ('A', 'B', 'C', 'D')

fig, ax = plt.subplots()
ax.p1 = plt.bar(index, means, width=width, color="red",
               linewidth=2, zorder=5, alpha=0.5)
ax.errs = plt.errorbar(index, means, yerr=std)

plt.ylim(ymax=60)
plt.xticks(index, labels, color='k')

plt.show()

輸出

更新於:2021年6月9日

443 次檢視

啟動您的職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.