Python3.6-在Matplotlib上绘制纬度/经度坐标

时间:2018-11-09 10:48:21

标签: python matplotlib

这是我第一次使用Matplotlib。我在两个列表中有一系列的纬度和经度坐标,我想以一种有意义的方式表示它们。我不想为several reasons使用底图。

lat = ['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951']
long = ['14.471970', '14.477780', '14.518173', '14.572245', '14.535320', '14.455894', '14.373217', '14.336096', '14.351006', '14.401137']

我正在尝试使用Matplotlib有意义地表示这些。

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.show()

但是我的数字如下:

enter image description here

我无法设置轴以获取这些坐标的有意义的表示。如何才能做到这一点?我在做什么错了?

我正在寻找这样的东西:

import numpy as np
import matplotlib.pyplot as plt

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

plt.scatter(x, y)
plt.show()

我得到了预期的结果。

enter image description here

我也曾尝试plot on a cartesian coordinate system


编辑:

根据以下评论:

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.axis('square')
plt.show()

enter image description here

1 个答案:

答案 0 :(得分:1)

如注释中所述,将类型更改为float:

import numpy as np
import matplotlib.pyplot as plt

lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', 
'35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
long = np.array(['14.471970', '14.477780', '14.518173', '14.572245', '14.535320', 
'14.455894', '14.373217', '14.336096', '14.351006', '14.401137'], dtype=float)

fig, ax = plt.subplots(figsize=(10, 6))
ax.scatter(lat, long)
# ax.axis('equal')
plt.show()

enter image description here