I am classifying points of the earth (lon and lat coordinates) into categories based on variables for that point. I have an array (360 x 720) (the resolution of my lat, lon grid for earth) that contains the appropriate classification for each point as a number, there are 13 categories; a, b, c,... and in my 360x 720 array these categories are represented as 1, 2, 3,..., 13.
I can map this via cartopy and matplotlib, but i am stuck trying to make a legend/ key that shows what category each color mapped represents, the best i can get is an unhelpful colorbar.
ax = plt.axes(projection=ccrs.PlateCarree()) #cartopy
preplot = plt.contourf(lons, lats, Map, 17,
transform=ccrs.PlateCarree(), cmap = "tab20")
ax.coastlines() # cartopy
cb = plt.colorbar(preplot, orientation="horizontal")
plt.title("1901")
plt.show()
which gives: enter image description here A map and colorbar
Sorry if this is not all the needed info