如何使用 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()

輸出

它將生成以下輸出 -

更新於: 2022 年 2 月 1 日

684 次瀏覽

啟動你的職業

完成課程後獲得認證證明

入門
廣告
© . All rights reserved.