Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Thiết lập phạm vi hiển thị subplot errorbars trong matplotlib


Để thiết lập phạm vi hiển thị subplot hoặc errorbars trong matplotlib, chúng ta có thể thực hiện các bước sau:

  • Thiết lập kích thước figure và điều chỉnh padding giữa và xung quanh subplots.
  • Tạo điểm dữ liệu x và y bằng numpy.
  • Tạo figure và tập subplots.
  • Vẽ y versus x dưới dạng lines và/hoặc markers với errorbars đính kèm.
  • Để hiển thị figure, dùng phương thức show().

Ví dụ

import numpy as np
import matplotlib.pyplot as plt

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

x = np.arange(0.1, 4, 0.5)
y = np.exp(-x)

fig, ax = plt.subplots()
ax.errorbar(x, y, xerr=0.2, yerr=0.4)

plt.show()

Kết quả

Thiết lập phạm vi hiển thị subplot errorbars trong matplotlibThiết lập phạm vi hiển thị subplot errorbars trong matplotlib