Trouble visualize GIS data with Geopandas.plot()

Question:

I want to visualize the GIS data about Iran accidents in googlecolab, I have latitude, longitude, and death_count information but when I try to read it as Geopaandas data frame the plot function is not working correctly, May you please advise me on this issue, I have 3720 rows and 3 columns, and the result of visualization is attached as a link, thanks in advance for your help.

import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpd
df = pd.read_excel("/content/accidents98.xlsx")
gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.longitude)و df.latitude))
gdf['death_count']] = gdf[['death_count']].fillna(value=0)
fig, ax = plt.subplots(1, figsize=(20, 20))
ax.axis('off')
ax.set_title('accidents in Iran',
             fontdict={'fontsize': '15', 'fontweight' : '3'})
fig = gdf.plot(column='death_count', cmap='RdYlGn', linewidth=0.5, ax=ax, edgecolor='0.2',legend=True)

the input:
input

the output:
output

Asked By: fatane

||

Answers:

You have points_from_xy(df.latitude , df.longitude). points_from_xy expects (x, y) not (y, x). You need to switch the lat/lon order to lon, lat

Answered By: Michael Delgado
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.