Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Plot a route in a map

I’m using python and I need to plot a route in a map. I have a dataframe that looks like this:

  latitude  longitude
  41.393095  -8.703483
  41.393095  -8.703483
  41.393095  -8.703483
  41.392483  -8.703088
  40.942170  -8.540572
  40.942188  -8.540567
  41.187624  -8.568143
  41.321009  -8.711874
  41.345618  -8.547567

The order of the dataframe represents the order of the route and I would like to plot it based on latitude and longitude. But i only find ways to plot it based on osm node IDs.

Does anyone know a way of plotting this route with the exact geographic coordinates?
Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Using This tutorial, I managed to plot the points on a map:

Image of map with path

# Create a bounding box to determine the size of the required map
BBox = (df.longitude.min()-0.1,   df.longitude.max()+0.1,
        df.latitude.min()-0.1, df.latitude.max()+0.1)

# Downloaded using this tutorial: https://medium.com/@abuqassim115/thanks-for-your-response-frank-fb869824ede2
map_img = plt.imread('map.png')

# Plotting the points on the graph
fig, ax = plt.subplots(figsize=(8, 7))
ax.plot(df.longitude, df.latitude, 'xb-')

# Setting limits for the plot
ax.set_xlim(BBox[0], BBox[1])
ax.set_ylim(BBox[2], BBox[3])

# Showing the image behind the points
ax.imshow(map_img, zorder=0, extent=BBox, aspect='equal')

plt.show()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading