matplotlib将一个excel矩阵画出九宫图
姓名 无法操作 不熟练 熟练 非常熟练 组装类 0 3 9 19 手工编制类 1 3 24 3 新娘发饰类 0 6 21 4 布艺类 10 16 4 1 胶水粘贴类 0 5 22 4 平车 20 2 6 3 点钻 3 6 13 9 发绣 4 7 20 0 刺绣 24 7 0 0
import pandas as pd
import matplotlib. pyplot as plt
plt. rcParams[ 'font.sans-serif' ] = [ 'SimHei' ]
plt. rcParams[ 'axes.unicode_minus' ] = False
df= pd. read_excel( '.\匠人工人技能分类评价表.xlsx' , sheet_name= 'Sheet5' , index_col= '姓名' )
columns_name= df. columns. to_list( )
index_lst= df. index. to_list( )
df_new= df. stack( )
plt. figure( figsize= ( 12 , 8 ) , dpi= 120 )
for i in range ( len ( index_lst) ) :
ax= plt. subplot( 331 + i)
ax. bar( x= columns_name, height= df. loc[ index_lst[ i] ] . values, color= 'mediumseagreen' , alpha= 0.5 , label= index_lst[ i] )
ax. legend( )
for i, j in enumerate ( df. loc[ index_lst[ i] ] ) :
plt. text( i- 0.38 , j- 0.2 , f'{round(j/31*100)}%-{j}人' )
plt. savefig( 'capacity.png' )