ในการใส่ข้อความนอกโครงเรื่อง เราสามารถเปลี่ยนตำแหน่งข้อความโดยเปลี่ยนค่าของ text_pos_x และ text_pos_y
ขั้นตอน
- สร้างจุดข้อมูลสำหรับ x และ y
- เริ่มต้นตำแหน่งข้อความของ x และ y
- ในการลงจุด x และ y ให้ใช้วิธี plot() กับ color='red' .
- ใช้วิธี text() เพื่อเพิ่มข้อความให้กับภาพ
- หากต้องการแสดงรูป ให้ใช้ show() วิธีการ
ตัวอย่าง
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(1, 5, 100)
y = np.exp(x)
text_pos_x = 0.60
text_pos_y = 0.50
plt.plot(x, y, c='red')
plt.text(text_pos_x, text_pos_y, "$\mathit{y}=e^{x}$", fontsize=14,
transform=plt.gcf().transFigure, color='green')
plt.show() ผลลัพธ์
