【发布时间】:2019-05-20 01:12:31
【问题描述】:
我想制作我的条形图,以便我的颜色与类别匹配,只是我通过我的数据框进行切片和分组以重新组织它。已经用一些代码取得了一些成果。但是我的代码太古怪了,我想知道是否有办法让它变得更好。
pokecolor = {'Grass': '#78C850', 'Normal':'#A8A878','Fire':'#F08030','Fighting':'#C03028','Water':'#6890F0', 'Flying':'#A890F0','Poison':'#A040A0','Electric':'#F8D030','Ground':'#E0C068','Psychic':'#F85880','Rock':'#B8A038','Ice':'#98D8D8','Bug':'#A8B820','Dragon':'#7038F8','Ghost':'#705898','Dark':'#705848','Steel':'#B8B8D0','Fairy':'#EE99AC'}
df_poke['Type 1 color'] = df_poke['Type 1'].map(lambda x: pokecolor[x])
tipo1 = df_poke.loc[:,'Type 1'].value_counts(ascending=True)
tipo1.plot(kind='barh', grid=True, figsize=(15,8),
xticks= [n for n in range(0,111, 10)],
color=tipo1.reset_index()['index'].apply(lambda x : pokecolor[x]))
我不想使用“tipo1”,重置它的索引并应用 pokecolor 到它。
【问题讨论】:
标签: pandas matplotlib