怎么使用python在地图上绘制轨迹图_用matplotlib在地图图片上绘制轨迹

在不同的坐标系中有两对相互对应的点可以定义系统之间的转换。您可以将此转换添加到线条的数据转换中,以获得图像坐标中的线条。在import numpy as np

import matplotlib.pyplot as plt

from matplotlib.transforms import Affine2D

def get_transform_2pts(q1, q2, p1, p2):

""" create transform to transform from q to p,

such that q1 will point to p1, and q2 to p2 """

ang = np.arctan((p2-p1)[1] /(p2-p1)[0])-np.arctan((q2-q1)[1] /(q2-q1)[0])

s = np.abs(np.sqrt(np.sum((p2-p1)**2))/np.sqrt(np.sum((q2-q1)**2)))

trans = Affine2D().translate(*-q1).rotate(ang).scale(s).translate(*p1)

return trans

image = plt.imread("https://i.stack.imgur.com/ue5oH.png")

y0 = image.shape[0]

waypoints = [[0, -1, -4, -6, -6], [0, 0, 4, 4, 3]]

# Coordinates for transformation.

lc1 = np.array([0,0])

ic1 = np.array([475, y0-187])

lc2 = np.array([-1, 0])

ic2 = np.array([437, y0-194])

trans = get_transform_2pts(lc1, lc2, ic1, ic2)

fig, ax = plt.subplots()

ax.imshow(np.flipud(image), origin="lower")

plt.plot(waypoints[0], waypoints[1], 'o-', transform=trans+ax.transData)

ax.set_aspect("equal")

plt.show()

g4MGy.png

或者如果你只想在线上自动缩放

^{pr2}$

atiMW.png

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值