2x2子批次但只有3个图表如何移除最后一个平底锅

2024-10-02 18:27:04 发布

您现在位置:Python中文网/ 问答频道 /正文

four-panel chart with only three active charts

大家好

在上图中,如何卸下第四个面板?在

这是密码。有什么想法吗?在

panel, ax = plt.subplots(2,2)
ax[0,0].scatter(df[:,0],df[:,1],s=50)
ax[0,0].set_title('Original Scatter (middle 90%)')
ax[0,0].set_xlabel('Diversification index', fontsize=8) 
ax[0,0].set_ylabel('PPP per capita', fontsize=8)
ax[0,1].plot(K, bss/tss*100, 'b*-')
ax[0,1].plot([0,20],[90,90],'k-', color='red')
ax[0,1].set_title('Optimal number of clusters')
ax[0,1].set_xlabel('Number of clusters', fontsize=8)
ax[0,1].set_ylabel('% variance explained', fontsize=8)
ax[0,1].text(0.95,0.01, 'Elbow for KMeans clustering',
        verticalalignment='bottom', horizontalalignment='right',
        transform=ax[0,1].transAxes, color='red', fontsize=8)

clr = ['b','g','r','c','m','y','k']
 for i in range(K[kIdx-1]):
    ind = (cIdx[kIdx-1]==i)
    ax[1,0].scatter(df[ind,0],df[ind,1], s=30, c=clr[i], label='Cluster %d'%i)
ax[1,0].set_xlabel('Diversification index', fontsize=8)
ax[1,0].set_ylabel('GDP',fontsize=8)
ax[1,0].set_title('KMeans clustering with K=%d' % K[kIdx-1])
box = ax[1,0].get_position()
ax[1,0].set_position([box.x0, box.y0, box.width*0.8, box.height])
ax[1,0].legend(loc='center left',bbox_to_anchor=(1,0.5), fancybox=True, shadow=True)

Tags: boxdfindexplottitleaxcolorset