ในการตั้งค่าช่วงแสดงผล subplot หรือ errorbars ใน matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้:
- ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
- สร้างจุดข้อมูล x และ y ด้วย numpy
- สร้าง figure และชุด subplots
- พลอต y versus x เป็นเส้นและ/หรือเครื่องหมายพร้อม errorbars
- เพื่อแสดงรูป ใช้เมธอด show()
ตัวอย่าง
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()
ผลลัพธ์

