[Python] Geopandas not displaying map

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new to programming and I'm learning on my own so I'm sorry for any confusions... I need to make this map with frequencies and I have a shapefile, I merged the shapefile to the dbf file so I had the info on the states I needed. Then, I merged that to my excel file which has the data needed to get the map "coloured" and did the plot, the thing is my map is not showing, it's blank! I really don't know what to do, I've tried everything I could find online...

    I share my code:

    import geopandas as gpd
    import pandas as pd
    import matplotlib.pyplot as plt

    proj4_string = (
    "+proj=lcc +lat_1=17.5 +lat_2=29.5 +lat_0=12 +lon_0=-102 +x_0=2500000 +y_0=0 "
    "+a=6378137 +rf=298.257222101 +units=m +no_defs"
    )
    mx = gpd.read_file("/content/enti.shp")
    mx.crs = proj4_string
    mx.plot()
    print(mx)
    print(mx.columns)

    # Read the Excel data
    excel_path = '/content/BH2020.xlsx'
    df20 = pd.read_excel(excel_path)
    merged_data = pd.merge(mx, df20, left_on='CVE_ENT_x', right_on='Entidades', how='left')
    print(merged_data)

    # Create the plot
    merged_data.plot(column='TOTALES', cmap='Reds', linewidth=0.8, edgecolor='0.8', legend=True)

    # Set the title
    plt.title('Brucelosis en México 2020')

    # Show the plot
    plt.show()[enter link description here][1]


    This is my final result (https://i.sstatic.net/DKc6Y.png)

    Continue reading...

Compartilhe esta Página