在 Python Matplotlib 中显示图中的点坐标

matplotlibpythondata visualization更新于 2024/3/1 17:16:17

要在 Python 中显示图中的点坐标,我们可以采取以下步骤 −

步骤

  • 设置图形大小并调整子图之间和周围的填充。

  • 使用 numpy 初始化变量 N 并创建 x 和 y 数据点。

  • 压缩 x 和 y 数据点;迭代它们并放置坐标。

  • 要显示图形,请使用 show() 方法。

示例

import matplotlib.pyplot as plt
import numpy as np

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

N = 5

x = np.random.rand(N)
y = np.random.rand(N)

plt.plot(x, y, 'r*')

for xy in zip(x, y):
   plt.annotate('(%.2f, %.2f)' % xy, xy=xy)

plt.show()

输出

它将产生以下输出 −


相关文章


有用资源