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

ดึงค่า (x,y) ของเส้น Contour Plot ใน Matplotlib

ใช้ contour() ได้ collections → get_paths() → vertices ของแต่ละ path

ตัวอย่างโค้ด


import matplotlib.pyplot as plt

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

m = [[3, 2, 1, 0], [2, 4, 1, 0], [2, 4, 1, 3], [4, 3, 1, 3]]
cs = plt.contour([3, 4, 2, 1], [5, 1, 2, 3], m)

p1 = cs.collections[0].get_paths()
for item in p1:
    print(item.vertices)

plt.show()

ผลลัพธ์

พิมพ์พิกัด vertices ของเส้น contour ระดับแรก

ดึงค่า (x,y) ของเส้น Contour Plot ใน Matplotlib