ในการจัดรูปแบบทุ่นโดยใช้ฟอร์แมตเตอร์ LaTeX ของ matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้ -
ขั้นตอน
-
กำหนดขนาดรูปและปรับช่องว่างภายในระหว่างและรอบๆ แผนผังย่อย
-
สร้างจุดข้อมูล x และ y โดยใช้ numpy
-
พล็อตจุดข้อมูล x และ y โดยใช้ plot() วิธีการ
-
เติมพื้นที่ระหว่างเส้นโค้ง
-
ตั้งชื่อภาพด้วยการแสดง LaTeX
-
หากต้องการแสดงรูป ให้ใช้ show() วิธีการ
ตัวอย่าง
import numpy as np
from matplotlib import pyplot as plt
# Set the figures size
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
# x and y data points
x = np.linspace(-5, 5, 100)
y = x**3/3
# Plot the data points
plt.plot(x, y)
# Fill the area between the curve
plt.fill_between(x, y)
# LaTex representation
plt.title("$area=\int_a^b{x^2dx}$=83.3")
# Display the plot
plt.show() ผลลัพธ์
มันจะสร้างผลลัพธ์ต่อไปนี้ -
