Plot latitude longitude from CSV in Python 3.6
If you are just looking at plotting the point data as a scatterplot, is as simple as
import matplotlib.pyplot as pltplt.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 pdfrom shapely.geometry import Pointimport geopandas as gpdfrom geopandas import GeoDataFramedf = 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 geopandasworld = 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 pximport pandas as pddf = 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()