I have conducted a KMeans clustering on a NetCDF data with dimensions (longitude*latitude, time)
np.random.seed(1)
kmeans = KMeans(init='k-means++', n_clusters=5, n_init=10)
kmeans.fit(eofs) # eofs is input of size (4303,5)
code = kmeans.labels_
plt.clf() #clear figure before
fig=plt.figure(figsize=(8,5))
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=100.0, globe=None))
ax.set_extent([96,105,1,8]) # lon_left, lon_right, lat_below, lat_upper
ax.gridlines(linewidths=0.01, draw_labels=True, alpha= 0.3)
ax.xlocator = mticker.FixedLocator(np.arange(96.,105.,0.5))
ax.ylocator = mticker.FixedLocator(np.arange(1.,8.,0.5))
clevs = np.arange(-0.5,5,1)
cs = ax.contourf(coords[0], coords[1], code_recons[0], clevs, cmap="Accent", transform=ccrs.PlateCarree())
ax.coastlines("50m") # avail:110m, 50m, 10m..... '10m' is better resolution than default
cax = fig.add_axes([0.21,0.05,0.6,0.03]) #plot cb at the bottom [left, bottom, width, height]
ba =fig.colorbar(cs,cax=cax,orientation='horizontal')
n_clusters=5
tick_locs = (np.arange(n_clusters) + 0.5)*(n_clusters-1)/n_clusters
ba.set_ticks(tick_locs)
ba.set_ticklabels(np.arange(1,n_clusters+1))
ba.set_label("Region")
The plot of 5 clustersenter image description here
As you can see, the clusters are not as discreet as I would have wanted, but I would like to draw a black border to delineate the 5 clusters and further categorise the points that seem to "leak" from the center to be put in appropriate (nearer) cluster.