如何在 Matplotlib 中強制渲染錯誤線?


要強制錯誤線在 Matplotlib 中最後渲染,我們可以採取以下步驟 -

  • 設定圖形大小並調整子圖之間和周圍的邊距。
  • 使用 figure() 方法建立一個新圖形或啟用一個現有圖形。
  • 使用 gca() 方法獲取當前軸。
  • 繪製線條列表
  • y 作為線條和/或標記與附加的錯誤線繪製為 x
  • 要顯示圖形,請使用 show() 方法。

示例

import matplotlib.pyplot as plt
import numpy as np

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

fig = plt.figure()
ax = plt.gca()

[ax.plot(np.random.rand(10)) for j in range(10)]
ax.errorbar(range(10), np.random.rand(10), yerr=.3 * np.random.rand(10))

plt.show()

輸出

更新日期: 05-6-2021

87 次瀏覽

開始你的職業

完成課程,獲得認證

開始
廣告
© . All rights reserved.