Python:可视化字典的最佳方法 [英] Python: Best way to visualize dict of dicts
本文介绍了Python:可视化字典的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想形象化以下命令
players_info = {'阿富汗':{'Asghar Stanikzai':809.0 ,
穆罕默德·纳比:851.0,
穆罕默德·沙赫扎德:1713.0,
纳吉布拉·扎德兰:643.0,
萨穆拉·申瓦里:774.0},
'澳大利亚':{'AJ Finch':1082.0,
'CL White':988.0,
'DA Warner':1691.0,
'GJ Maxwell':822.0,
' SR沃森('Watson'):1465.0},
'英国':{'AD Hales':1340.0,
'EJG Morgan':1577.0,
'JC Buttler':985.0,
' KP Pietersen':1176.0,
'LJ Wright':759.0}}
当前我是使用以下方法,但使用较大的字典,却使我不希望出现混乱情况。
将熊猫作为pd $ b导入$ b导入matplotlib.pyplot as plt
pd.DataFrame(players_info).plot.bar()
plt.show()
请提出一种更好的可视化方法。谢谢
解决方案我建议使用
I want to visualize the following dict of dicts
players_info = {'Afghanistan': {'Asghar Stanikzai': 809.0, 'Mohammad Nabi': 851.0, 'Mohammad Shahzad': 1713.0, 'Najibullah Zadran': 643.0, 'Samiullah Shenwari': 774.0}, 'Australia': {'AJ Finch': 1082.0, 'CL White': 988.0, 'DA Warner': 1691.0, 'GJ Maxwell': 822.0, 'SR Watson': 1465.0}, 'England': {'AD Hales': 1340.0, 'EJG Morgan': 1577.0, 'JC Buttler': 985.0, 'KP Pietersen': 1176.0, 'LJ Wright': 759.0}}
Currently I am using the following way but with large dict it is making a clutter which I don't want.
import pandas as pd import matplotlib.pyplot as plt pd.DataFrame(players_info).plot.bar() plt.show()
Please suggest a better way of visualizing it. Thanks
解决方案I suggest using
heatmap
.import pandas as pd import seaborn as sns sns.set(rc={"figure.figsize":(12,8)}) df = pd.DataFrame(players_info) g = sns.heatmap(df, cmap="Blues", annot=True, fmt='g') g.get_figure().savefig("heatmap.png")
Output:
这篇关于Python:可视化字典的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文