pythonmatplotlibgisgeopandascolormap

Matplotlib colormap not showing in legend


I was working on this introduction to geospatial data analysis with Python. I've replicated each line of code in my own Jupyter notebook and have obtained the same results except for the last graph. The code for the graph is:

fig, ax = plt.subplots(1, figsize=(20,20))
base = country[country['NAME'].isin(['Alaska','Hawaii']) == False].plot(ax=ax, color='#3B3C6E')
florence.plot(ax=base, column='Wind', marker="<", markersize=10, cmap='cool', label="Wind speed(mph)")
_ = ax.axis('off')
plt.legend()
ax.set_title("Hurricane Florence in US Map", fontsize=25)
plt.savefig('Hurricane_footage.png',bbox_inches='tight')

and should yield the following graph :

It's the path of Hurricane Florence in the United States.

However, when I copy that line of code in my notebook the legend is not working :

Notice how the legend is not giving the color codes for wind velocity

I thought it was my version of matplotlib so I updated it, but it's still not working. I don't see what else could be wrong.


Solution

  • They must be doing some classification by quantiles that wasn't covered in their tutorial :

    fig, ax = plt.subplots(1, figsize=(20, 20))
    
    base = (
        country[country["NAME"].isin(["Alaska", "Hawaii"]) == False].plot(
        ax=ax, color="#3B3C6E"
        )
    )
    
    florence.plot(
        ax=base,
        column="Wind",
        marker="<",
        markersize=10,
        cmap="cool",
        scheme="Quantiles",
        legend=True,
        legend_kwds={"title": "Wind speed(mph)"}, 
    )
    
    _ = ax.axis("off")
    
    ax.set_title("Hurricane Florence in US Map", fontsize=25)
    
    plt.savefig("Hurricane_footage.png", dpi=300, bbox_inches="tight")
    

    enter image description here