Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

Error bars โปร่งใสโดยไม่กระทบ markers ใน Matplotlib

ในการทำ error bars โปร่งใสโดยไม่กระทบ markers ใน matplotlib สามารถทำตามขั้นตอนดังนี้:

ขั้นตอน

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots

  • สร้างรายการ x, y และ z สำหรับข้อมูล

  • เริ่มต้นตัวแปร error_bar_width=5

  • วาด y versus x เป็นเส้นและ/หรือ markers พร้อม errorbars

  • ตั้งค่า alpha ของ bars และ caps

  • แสดงรูปด้วยเมธอด show()

ตัวอย่าง

from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = [1, 3, 5, 7]
y = [1, 3, 5, 7]
z = [4, 5, 1, 4]
error_bar_width = 5
markers, caps, bars = plt.errorbar(x, y, z, capsize=5, elinewidth=error_bar_width,
                                    markeredgewidth=7, fmt='o', ecolor='black', capthick=2)
[bar.set_alpha(0.5) for bar in bars]
[cap.set_alpha(0.5) for cap in caps]
plt.show()

ผลลัพธ์

จะแสดง error bars โปร่งใส (alpha=0.5) แต่ markers คงอัลฟาเต็ม

Error bars โปร่งใสโดยไม่กระทบ markers ใน Matplotlib