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