You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将给定坐标点集合平移,使matplotlib绘图坐标轴范围从原点开始

坐标平移实现方案

核心逻辑

要让坐标轴范围从原点开始,只需对所有坐标点做整体平移:所有x值减去x坐标的最小值,所有y值减去y坐标的最小值。平移后点的相对位置完全不变,且新坐标的最小值均为0,绘图时坐标轴自然会从原点开始展示。

完整实现代码

import matplotlib.pyplot as plt
xpos = [2419, 2597, 2678, 2691, 2967, 3350, 2227.5, 2781.0, 2278]
ypos = [4687, 4784, 4986, 4479, 4873.5, 3250, 4109, 3329, 3507]

# 平移处理
x_min = min(xpos)
y_min = min(ypos)
xpos_trans = [x - x_min for x in xpos]
ypos_trans = [y - y_min for y in ypos]

plt.plot(xpos_trans, ypos_trans, '*')
# 可选:强制设置坐标轴从(0,0)开始,避免matplotlib自动加内边距
plt.xlim(left=0)
plt.ylim(bottom=0)
plt.show()

效果说明

  • 平移后的x坐标范围为 0 到 max(xpos) - min(xpos)(即1122.5)
  • 平移后的y坐标范围为 0 到 max(ypos) - min(ypos)(即1736)
  • 点的相对分布和原始效果完全一致,仅整体位置移动到以原点为左下角的范围内

原始坐标点效果图如下:
坐标点效果图

内容的提问来源于stack exchange,提问作者Natasha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 12:45:05