我试图在地图图像上绘制一些坐标(纬度和经度)。我正在绘制的数据来自列表列表(lats和lons分别是第2和第3个元素)。 我已经做了一些关于matplotlib和'extent'的阅读,但是我仍然无法将坐标与地图对齐(也就是说,我无法将其缩放'可以这么说'。
def mapping_data(atlas_data):
i = 0
x = []
y = []
while i < len(atlas_data):
x.append(atlas_data[i][1])
y.append(atlas_data[i][2])
i = i + 1
image = plt.imread('map.png')
mapped = plt.imshow(image)
plt.imshow(mpimg.imread('map.png'))
plt.scatter(x, y)
plt.show()
当我按原样运行我的代码时,我得到了im1(地图正常,但是所有地点都指向地图而不是地图上)。当我添加所需的地图范围时,如下所示:
(plt.imshow(mpimg.imread('map.png'), extent = (149.105, 149.130, -35.29, -35.27))
...我得到了im2(像往前一样,但是地图图像颠倒了)??
有人可以帮我解决出错的问题吗?我错过了一步吗?我非常感谢任何有助于调整事物的帮助!
以下是我用于参考的数据示例:
[['Kookaburra',
-35.27667,
149.1097,
'Australian National Botaniacl Gardens, Canberra',
'2000-08-14',
'Aves',
'Coraciiformes',
'Alcedinidae',
'Dacelo',
'Dacelo novaeguineae',
'False'],
['White-faced heron',
-35.272244105599064,
149.12580246473127,
'Sullivans Creek--Turner Parkland',
'2016-08-09',
'Aves',
'Ciconiiformes',
'Ardeidae',
'Egretta',
'Egretta novaehollandiae',
'False'],
['Australian King-parrot',
-35.274386,
149.112636,
'CSIRO (Black Mountain)',
'2014-10-20',
'Aves',
'Psittaciformes',
'Psittacidae',
'Alisterus',
'Alisterus scapularis',
'False'],
['Eastern Spinebill',
-35.27719917903922,
149.10937031732462,
'Australian National Botanic Gardens',
'2000-09-08',
'Aves',
'Passeriformes',
'Meliphagidae',
'Acanthorhynchus',
'Acanthorhynchus tenuirostris',
'False'],
['Crimson Rosella',
-35.2780499,
149.11015749999999,
'Australian National Botanic Gardens',
'2003-08-08',
'Aves',
'Psittaciformes',
'Psittacidae',
'Platycercus',
'Platycercus elegans',
'False'],
['Australian Raven',
-35.27856893080605,
149.10974594347084,
'Australian National Botanic Gardens',
'2018-03-18',
'Aves',
'Passeriformes',
'Corvidae',
'Corvus',
'Corvus coronoides',
'False'],
['Australian King-parrot',
-35.2780499,
149.11015749999999,
'Australian National Botanic Gardens',
'2012-07-24',
'Aves',
'Psittaciformes',
'Psittacidae',
'Alisterus',
'Alisterus scapularis',
'False']]
答案 0 :(得分:0)
您快到了那里! x和y需要交换。我还整理了一下您的功能。
以下方法应该起作用:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
fig, ax = plt.subplots()
atlas_data = [['Kookaburra',
-35.27667,
149.1097,
'Australian National Botaniacl Gardens, Canberra',
'2000-08-14',
'Aves',
'Coraciiformes',
'Alcedinidae',
'Dacelo',
'Dacelo novaeguineae',
'False'],
['White-faced heron',
-35.272244105599064,
149.12580246473127,
'Sullivans Creek--Turner Parkland',
'2016-08-09',
'Aves',
'Ciconiiformes',
'Ardeidae',
'Egretta',
'Egretta novaehollandiae',
'False'],
['Australian King-parrot',
-35.274386,
149.112636,
'CSIRO (Black Mountain)',
'2014-10-20',
'Aves',
'Psittaciformes',
'Psittacidae',
'Alisterus',
'Alisterus scapularis',
'False'],
['Eastern Spinebill',
-35.27719917903922,
149.10937031732462,
'Australian National Botanic Gardens',
'2000-09-08',
'Aves',
'Passeriformes',
'Meliphagidae',
'Acanthorhynchus',
'Acanthorhynchus tenuirostris',
'False'],
['Crimson Rosella',
-35.2780499,
149.11015749999999,
'Australian National Botanic Gardens',
'2003-08-08',
'Aves',
'Psittaciformes',
'Psittacidae',
'Platycercus',
'Platycercus elegans',
'False'],
['Australian Raven',
-35.27856893080605,
149.10974594347084,
'Australian National Botanic Gardens',
'2018-03-18',
'Aves',
'Passeriformes',
'Corvidae',
'Corvus',
'Corvus coronoides',
'False'],
['Australian King-parrot',
-35.2780499,
149.11015749999999,
'Australian National Botanic Gardens',
'2012-07-24',
'Aves',
'Psittaciformes',
'Psittacidae',
'Alisterus',
'Alisterus scapularis',
'False']]
def mapping_data(atlas_data):
x, y = [], []
for i in range(len(atlas_data)):
x.append(atlas_data[i][1])
y.append(atlas_data[i][2])
return x, y
y, x = mapping_data(atlas_data)
ax.scatter(x, y, edgecolors='red', linewidths=2, zorder=2)
ax.imshow(mpimg.imread('https://preview.ibb.co/jSD99o/map.png'), extent=(149.105, 149.130, -35.29, -35.27), zorder=1)
plt.show()
仅供参考,我创建了指向该区域google地图上的屏幕截图的链接,因此,实际位置是估算值,坐标将不完全匹配。