如何在 Matplotlib 中獲取反向順序累積直方圖?


要獲取 Matplotlib 中的反向順序累積直方圖,我們可以在 **hist()** 方法中使用 **cumulative = -1**。

  • 設定圖片大小並調整子圖之間和周圍的間距。
  • 列出資料點。
  • 使用 **data** and **cumulative = -1** 繪製直方圖。
  • 使用 **show()** 方法顯示圖片。

示例

from matplotlib import pyplot as plt

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

data = [1, 2, 2, 3, 1, 4, 3, 0, 1, 3, 0]

plt.hist(data, edgecolor='black', align="mid", cumulative=-1)

plt.show()

輸出

更新日期:07-Jul-2021

2K+ 瀏覽

開啟您的 職業

完成課程,獲得認證

開始
廣告
© . All rights reserved.