目錄
關鍵代碼:?
運行結果:
關鍵代碼:?
# 4. 按序號展示社團星級分布 - 熱力圖樣式
plt.subplot(2, 2, 4)
# 創建星級映射為數值
star_mapping = {'五星':4, '四星':3, '三星':2, '星級入圍':1}
star_values = df['答辯結果'].map(star_mapping)
plt.scatter(df['序號'], [1]*len(df), c=star_values, cmap='YlOrBr', s=500, alpha=0.7)
plt.yticks([])
plt.title('按序號展示社團星級分布(熱力圖)', fontproperties=zh_font)
plt.xlabel('序號', fontproperties=zh_font)
# 添加顏色條
cbar = plt.colorbar()
cbar.set_ticks([1, 2, 3, 4])
cbar.set_ticklabels(['星級入圍', '三星', '四星', '五星'])
cbar.ax.set_ylabel('星級', fontproperties=zh_font)plt.tight_layout()
plt.show()# 額外可視化:按序號展示社團名稱和星級
plt.figure(figsize=(12, 6))
# 創建星級顏色映射
colors = [star_colors[star] for star in df['答辯結果']]
bars = plt.barh(df['序號'], df['社團人數'], color=colors)
plt.title('按序號展示社團名稱和星級', fontproperties=zh_font)
plt.xlabel('社團人數', fontproperties=zh_font)
plt.ylabel('序號', fontproperties=zh_font)
# 在條形上添加社團名稱
for i, bar in enumerate(bars):width = bar.get_width()plt.text(width + 5, bar.get_y() + bar.get_height()/2, df.loc[i, '社團名稱'], ha='left', va='center', fontproperties=zh_font)
# 添加圖例
legend_elements = [plt.Rectangle((0,0),1,1, color='gold', label='五星'),plt.Rectangle((0,0),1,1, color='silver', label='四星'),plt.Rectangle((0,0),1,1, color='peru', label='三星'),plt.Rectangle((0,0),1,1, color='lightgray', label='星級入圍')]
plt.legend(handles=legend_elements, prop=zh_font, loc='lower right')
plt.grid(True, linestyle='--', alpha=0.3)
plt.show()
運行結果:
?
聲明:著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。