Tp ต่อท้ายเครื่องหมายติ๊กเดี่ยวที่แกน X โดยใช้ matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้ได้
ขั้นตอน
-
กำหนดขนาดรูปและปรับช่องว่างภายในระหว่างและรอบๆ แผนผังย่อย
-
สร้าง x และ ย จุดข้อมูลโดยใช้ numpy
-
พล็อตจุดข้อมูล x และ y โดยใช้ plot() วิธีการ
-
ตั้งค่า xticks ณ จุดเดียว
-
ตั้งค่า ป้ายกำกับ สำหรับขีดเดียว
-
หากต้องการแสดงรูป ให้ใช้ แสดง() วิธีการ
ตัวอย่าง
import numpy as np
import matplotlib.pyplot as plt
# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
# Create x and y data points
x = np.linspace(-5, 5, 50)
y = np.sin(x)
# Plot x and y data points
fig, ax = plt.subplots(1, 1)
p = ax.plot(x, y)
# Set xticks at a point
ax.set_xticks([-1.075])
# Set xticklabels for the point
ax.set_xticklabels(["$\\bf{It\ is -\!1.075\ label}$"])
# Display the plot
plt.show()
ผลลัพธ์
มันจะสร้างผลลัพธ์ต่อไปนี้ -
