我想制作我的条形图,以便我的颜色与类别相匹配,只是我正在根据我的数据帧对其进行切片和分组,以重新组织它。通过一些代码已经取得了一些成果。但是我的代码太古怪了,我想知道是否有什么方法可以让它变得更好。
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应用到它。
https://stackoverflow.com/questions/56209310
复制相似问题