[Python] How do I make alterations to this shapefile in python with geopandas or cartopy?

Discussão em 'Python' iniciado por Stack, Dezembro 6, 2024.

  1. Stack

    Stack Membro Participativo

    How do I add light grey state lines, change the background to white, and change certain areas to certain colors? This is from the EPA Level2 ecoregion map. I'd like to color each ecoregion a separate color.

    [​IMG]

    import geopandas as gpd
    import matplotlib.pyplot as plt

    # Load the shapefile
    shapefile_path = "/home/student/tsjohnson/NA_CEC_Eco_Level2.shx"
    level2 = gpd.read_file(shapefile_path)

    # Create the plot
    ax = level2.plot(edgecolor='black', figsize=(10, 8))

    # Set axis limits
    ax.set_xlim([-2.25E6,-1E6])
    ax.set_ylim([-1E6, 0.6E6])

    # Show the plot
    plt.show()


    I tried this and it stretched the image and didnt add anything.

    import geopandas as gpd
    import matplotlib.pyplot as plt

    # Load the shapefile
    shapefile_path = "/home/student/tsjohnson/NA_CEC_Eco_Level2.shx"
    level2 = gpd.read_file(shapefile_path)

    # Create the plot with white background
    fig, ax = plt.subplots(figsize=(10, 8))
    level2.plot(ax=ax, edgecolor='black')
    # Set axis limits
    ax.set_xlim([-2.25E6, -1E6])
    ax.set_ylim([-1E6, 0.5E6])
    ax.set_facecolor('white')
    us_states = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
    states = us_states[us_states['continent'] == 'North America'] # Filter for North American states

    states.boundary.plot(ax=ax, linewidth=1, color='black')

    plt.show()

    Continue reading...

Compartilhe esta Página