在 Matplotlib 中自动定位文本框
matplotlibserver side programmingprogramming更新于 2025/9/8 9:44:00
要在 matplotlib 中自动定位文本框,我们可以采取以下步骤 −
从 1 到 2 和 100 个样本创建 xpoints 。
使用 xpoints(步骤 1)和 numpy 创建 y1points 和 y2points。
使用 plot() 方法绘制 xpoints、y1points 和 y2points 。
要设置标签,请使用 legend() 方法。它将有助于定位文本框。
要显示图形,请使用 show() 方法。
示例
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True xpoints = np.linspace(1, 2, 100) y1points = np.log(xpoints) y2points = np.exp(xpoints) plt.plot(xpoints, y1points, label="Log") plt.plot(xpoints, y2points, label="Exp") plt.legend() plt.show()
输出


