ในการแสดงพิกัดจุดบน plot ใน Python สามารถทำตามขั้นตอนดังนี้:
ขั้นตอน
ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
เริ่มต้นตัวแปร N และสร้างข้อมูล x, y ด้วย numpy
Zip x และ y; วนลูปและวางพิกัดด้วย annotate
แสดงรูปด้วยเมธอด show()
ตัวอย่าง
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
N = 5
x = np.random.rand(N)
y = np.random.rand(N)
plt.plot(x, y, 'r*')
for xy in zip(x, y):
plt.annotate('(%.2f, %.2f)' % xy, xy=xy)
plt.show()
ผลลัพธ์
จะแสดงจุดสีแดง 5 จุด พร้อมป้ายพิกัด (x, y) 2 ตำแหน่งทศนิยม
