我想可视化下面的字典
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}}
目前我正在使用以下方式,但使用大字典会造成困惑,这是我不希望的。
import pandas as pd
import matplotlib.pyplot as plt
pd.DataFrame(players_info).plot.bar()
plt.show()
请建议一种更好的可视化方法。谢谢
最佳答案
我建议使用 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")
关于pandas - python : Best way to visualize dict of dicts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50614222/