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

แสดงพิกัดจุดบน Plot ใน Python ด้วย Matplotlib

ในการแสดงพิกัดจุดบน plot ใน Python เราสามารถทำตามขั้นตอนต่อไปนี้:

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
  • สร้างลิสต์ของ x และ y จุดข้อมูล
  • พลอต x และ y ด้วยสีแดงและ marker ดาว
  • ตั้งค่าคุณสมบัติแกนบางอย่าง
  • วนลูป x และ y เพื่อแสดงพิกัดบน plot

ตัวอย่าง

import matplotlib.pyplot as plt

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

x = [3, 1, 2, 5]
y = [5, 2, 4, 7]

plt.plot(x, y, 'r*')
plt.axis([0, 6, 0, 20])

for i, j in zip(x, y):
    plt.text(i, j+0.5, '({}, {})'.format(i, j))

plt.show()

ผลลัพธ์

แสดงพิกัดจุดบน Plot ใน Python ด้วย Matplotlib