I am getting a "ValueError: aspect must be finite and positive" error when I try to plot football stadium locations on a map.The weird thing is that I get the error when I attempt to plot Ukraine, Poland, or Hungary. But when I plot Germany, Italy, or the UK, the outcome is correct.
When I remove this line of codestadiums_gdf.set_crs(epsg=4326, inplace=True) the data is plotted correctly for Ukraine, Poland, and Hungary too, only the crs is not WGS84. So for some reason setting crs to WGS84 doesn't work for Ukraine, Poland, and Hungary.
My csv files are basically identical for all countries, the only difference are the coordinates of stadium locations.
import geopandas as gpdimport matplotlib.pyplot as pltfrom shapely.geometry import Pointimport pandas as pd# Lenovoworld = gpd.read_file(r'W:\FOR\RCO\DNI\Projects\ofedyshy\Personal\Data Analysis\fu\country_data\0.Geodata\ne_10m_admin_1_states_provinces\ne_10m_admin_1_states_provinces.shp')# Set CRS for stadiums_gdfworld.set_crs(epsg=4326, inplace=True) # Lenovourban_area = gpd.read_file(r'W:\FOR\RCO\DNI\Projects\ofedyshy\Personal\Data Analysis\0.Geo_Data\NaturalEarth\ne_10m_urban_areas\ne_10m_urban_areas.shp')# Lenovocsv_file = r'W:\FOR\RCO\DNI\Projects\ofedyshy\Personal\Data Analysis\fu\country_data\ua\ua_stad_by_decade_joined.csv' # # Define columns and values you want to see on the mapfield_of_interest = 'pts_sum' #<--------------------------------------------------------------- value_of_interest = 10# Define marker sizesvalue_1 = 2100 # =90% to 100% #<--------------------------------------------------------------- value_2 = 1600 # >70% value_3 = 1150 # >50% value_4 = 700 # >30%value_5 = 350 # >15%value_6 = 5 # >1%markersize_1 = 250markersize_2 = 140markersize_3 = 100markersize_4 = 50markersize_5 = 15markersize_6 = 5# colorsorange = '#DD6E42'dark_blue = '#2A4854'blue = '#4F6D7A'light_blue = '#C0D6DF'light_gray = '#f0f0f0'midnight_blue = '#212F3C'stadiums = pd.read_csv(csv_file, encoding='iso-8859-2')# Main map size and polygon outline sizewidth = 8height = 8poly_line_width = 0.3# Filter countrycountry = world.loc[(world['iso_a2'].isin(['UA']))]# Group the data by regionscountry_regions = country.dissolve(by='woe_name') #--------------------------------------------------------------------------------------------------------------------------------------------stadiums['long'] = pd.to_numeric(stadiums['long'], errors='coerce')stadiums['lat'] = pd.to_numeric(stadiums['lat'], errors='coerce')# Convert latitude and longitude columns to Point geometrystadiums['geometry'] = [Point(xy) for xy in zip(stadiums['long'], stadiums['lat'])]# Convert DataFrame to GeoDataFramestadiums_gdf = gpd.GeoDataFrame(stadiums, geometry='geometry')# Set CRS for stadiums_gdfstadiums_gdf.set_crs(epsg=4326, inplace=True) # Create GeoDataFrames for the field of interest where Canary Islands teams are absentfield_gdf = stadiums_gdf[stadiums_gdf[field_of_interest] >= value_of_interest]#-------------------------------------------------------------------------------------------------------------------------------------# Plot the main mapfig, ax = plt.subplots(figsize=(width, height)) # (width, height) in inchescountry_regions.plot(ax=ax, color=light_gray, edgecolor=midnight_blue, linewidth=poly_line_width, zorder=1)#-------------------------------------------------------------------------------------------------------------------------------------# Plot stadium locations based on conditions 15,8,6,1field_gdf.loc[field_gdf[field_of_interest] >= value_1].plot(ax=ax, color=orange, markersize=markersize_1, label='_', edgecolor='black', linewidth=0.5)field_gdf.loc[(field_gdf[field_of_interest] >= value_2) & (field_gdf[field_of_interest] < value_1)].plot(ax=ax, color=dark_blue, markersize=markersize_2, label='_', edgecolor='black', linewidth=0.5)field_gdf.loc[(field_gdf[field_of_interest] >= value_3) & (field_gdf[field_of_interest] < value_2)].plot(ax=ax, color=blue, markersize=markersize_3, label='_', edgecolor='black', linewidth=0.5)field_gdf.loc[(field_gdf[field_of_interest] >= value_4) & (field_gdf[field_of_interest] < value_3)].plot(ax=ax, color=light_blue, markersize=markersize_4, label='_', edgecolor='black', linewidth=0.4)field_gdf.loc[(field_gdf[field_of_interest] >= value_5) & (field_gdf[field_of_interest] < value_4)].plot(ax=ax, color=light_gray, markersize=markersize_5, label='_', edgecolor='black', linewidth=0.4)field_gdf.loc[(field_gdf[field_of_interest] >= value_6) & (field_gdf[field_of_interest] < value_5)].plot(ax=ax, color=light_gray, markersize=markersize_6, label='_', edgecolor='black', linewidth=0.3)# Customize plotplt.axis('off')plt.grid(False)plt.show()I will appreciate any feedback.Thanks
I tried grouping countries by region country_regions = country.dissolve(by='region').I also removed all the data for Ukraine in my csv file except for two stadium locations, but the error persists.