如何使用 matplotlib 的 LaTeX 格式化程式格式化浮點數?
要使用 matplotlib 的 LaTeX 格式化程式對浮點數進行格式化,我們可以採取以下步驟 -
步驟
設定圖形大小並調整子圖之間和周圍的填充。
使用 numpy 建立 x 和 y 資料點。
使用 **plot()** 方法繪製 x 和 y 資料點。
填充曲線之間的區域。
使用 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()輸出
它將生成以下輸出 -

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP