I'm trying to plot a large number of latitude longitude values from a CSV
file on a map, having this format (first column and second column):
I'm using python 3.6 (apparently some libraries like Basemap
doesn't operate on this version).
How can I do that?
gmplot is a matplotlib-like interface to generate the HTML and javascript to render all the data user would like on top of Google Maps. # latitude and longitude of given location . Code #3 : Scatter points on the google map and draw a line in between them .
Weird world. If you are just looking at plotting the point data as a scatterplot, is as simple as import matplotlib.pyplot as plt plt.scatter (x=df ['Longitude'], y=df ['Latitude']) plt.show () If you want to plot the points on the map, it's getting interesting because it depends more on how you plot your map.
To graph our longitude and latitude data we can use plotly’s “scatter_geo” function. This function is basically a scatter graph, but with an in-built geographical map that is overlayed below the scatter graph, which makes it easier for representation.
Plotly: Plot Geographical Data using a plotly scatter graph Another way to graph our geospatial data is using a python library called “plotly”. Plotly is a well-known python library because of its ability to provide more graphical tools and functions compared to matplotlib.
Longitude and latitude data are geographical points in a map, this is also known as geospatial data, the latitude and longitude data points allow us to pinpoint an exact location of a place within the world.
If you are just looking at plotting the point data as a scatterplot, is as simple as
import matplotlib.pyplot as plt
plt.scatter(x=df['Longitude'], y=df['Latitude'])
plt.show()
If you want to plot the points on the map, it's getting interesting because it depends more on how you plot your map.
A simple way is to use shapely
and geopandas
. The code below is not tested given my limited access on the laptop I am currently using, but it should give you a conceptual roadmap.
import pandas as pd
from shapely.geometry import Point
import geopandas as gpd
from geopandas import GeoDataFrame
df = pd.read_csv("Long_Lats.csv", delimiter=',', skiprows=0, low_memory=False)
geometry = [Point(xy) for xy in zip(df['Longitude'], df['Latitude'])]
gdf = GeoDataFrame(df, geometry=geometry)
#this is a simple map that goes with geopandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
gdf.plot(ax=world.plot(figsize=(10, 6)), marker='o', color='red', markersize=15);
Find below an example of the rendered image:
You can also use plotly express to plot the interactive worldmap for latitude and longitude
import plotly.express as px
import pandas as pd
df = pd.read_csv("location_coordinate.csv")
fig = px.scatter_geo(df,lat='lat',lon='long', hover_name="id")
fig.update_layout(title = 'World map', title_x=0.5)
fig.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With