失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 怎么使用python在地图上绘制轨迹图_用matplotlib在地图图片上绘制轨迹

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

时间:2022-11-27 15:48:02

相关推荐

怎么使用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./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()

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

^{pr2}$

如果觉得《怎么使用python在地图上绘制轨迹图_用matplotlib在地图图片上绘制轨迹》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。