使用 Matplotlib 在 Python 的绘图中显示点坐标
pythonserver side programmingprogramming更新于 2025/8/7 20:28:17
要在 Python 的绘图中显示点坐标,我们可以采取以下步骤 −
- 设置图形大小并调整子图之间和周围的填充。
- 创建 x 和 y 数据点的列表。
- 用红色和星号标记绘制 x 和 y 数据点
- 设置一些轴属性。
- 迭代 x 和 y 以在绘图上显示坐标。
示例
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = [3, 1, 2, 5]
y = [5, 2, 4, 7]
plt.plot(x, y, 'r*')
plt.axis([0, 6, 0, 20])
for i, j in zip(x, y):
plt.text(i, j+0.5, '({}, {})'.format(i, j))
plt.show()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

