Skip to content Skip to sidebar Skip to footer

Placing Coordinates On A Map - Python

I am trying to plot some coordinates (latitudes and longitudes) on top of an image of a map. The data I am plotting comes from a list of lists (the lats and lons are the 2nd and 3r

Solution 1:

You nearly got there! The x and y need to be swapped. I also cleaned up your function a bit.

map with coords

The following should work:

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']]

defmapping_data(atlas_data):
    x, y = [], []
    for i inrange(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()

FYI, I created a link to a screenshotted image from google maps in that area, so the actual location is estimated and the coordinates will not match exactly.

Post a Comment for "Placing Coordinates On A Map - Python"