fromcopyimportdeepcopyfrommatplotlibimportpyplotaspltimportmatplotlib.gridspecasgridspecfrompyalluvimportAlluvialPlot,Cluster,Flux# Create the sequence of clusteringstime_points=[0,4,9,14,18.2]# Define the cluster sizes per snapshot# at each time point {cluster_id: cluster_size})cluster_sizes=[{0:3},{0:5},{0:3,1:2},{0:5},{0:4}]# Define the membership fluxes between neighbouring clusteringsbetween_fluxes=[{(0,0):3},# key: (from cluster, to cluster), value: size{(0,0):3,(0,1):2},{(0,0):3,(1,0):2},{(0,0):4}]# set the colorscluster_color={0:"C1",1:"C2"}# create a dictionary with the time points as keys and a list of clusters# as valuesclustering_sequence={}fortp,clusteringinenumerate(cluster_sizes):clustering_sequence[time_points[tp]]=[Cluster(height=clustering[cid],label="{0}".format(cid),facecolor=cluster_color[cid],)forcidinclustering]# now create the fluxes between the clustersfortidx,tpinenumerate(time_points[1:]):fluxes=between_fluxes[tidx]forfrom_csid,to_csidinfluxes:Flux(flux=fluxes[(from_csid,to_csid)],source_cluster=clustering_sequence[time_points[tidx]][from_csid],target_cluster=clustering_sequence[tp][to_csid],facecolor='source_cluster')# ############################################################################## Create the figure# ############################################################################## with plt.xkcd():ifTrue:fig1=plt.figure(figsize=(6,4.2))gsCom=gridspec.GridSpec(9,16,left=0.05,wspace=2.0,hspace=2.0,top=0.99,bottom=0.07,right=0.95)# ############################################################################## The sankey illustration partalluvial_plot_params={'x_axis_offset':0.00,'redistribute_vertically':10,'with_cluster_labels':False,}ax_sk=fig1.add_subplot(gsCom[2:9,:],)ax_sk.axis('equal')ax_sk.set_xlim(0,25)ax_sk.set_ylim(-0.6,3)AlluvialPlot(clustering_sequence,ax_sk,**alluvial_plot_params)ax_sk.set_xticks(time_points,minor=False)ax_sk.set_xticklabels([r'$\mathbf{{t_{0}}}$'.format(idx)foridxinrange(6)],minor=False,size=9)ax_sk.tick_params(axis=u'x',which=u'both',length=0)# ########################################################################## Annotation part