0

I have the following nested dictionary

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}}

And I want to visualize it in the following way.

enter image description here

I have tried to convert it into a dataframe and then visualize but I am getting errors.

from pandas.tools.plotting import parallel_coordinates

df_plot = pd.DataFrame(players_info).stack().reset_index()
df_plot.columns = ['Player Name', 'Country', 'Total Score']
parallel_coordinates(df_plot, class_column='Country')

Error

ValueError: could not convert string to float: 'Asghar Stanikzai'

Is there a way in matplotlib or in seaborn where I can plot such a plot or similar. Please note that I want a similar plot not exactly like the one i meantioned. The idea is to plot the nested dict data in a better understandable way. Also please note that the dict here is just a small dict but in real data i have slightly bigger dict. Any suggestions will be highly appreciated.

muazfaiz
  • 4,611
  • 14
  • 50
  • 88
  • 2
    What have you tried so far? – user3483203 Jun 06 '18 at 23:17
  • I was trying some bar plots and have tried a heat map. I have a similar question https://stackoverflow.com/questions/50614222/python-best-way-to-visualize-dict-of-dicts/ but now I want to visualize this way and I don't know anyhting about the above mentioned plot :) – muazfaiz Jun 06 '18 at 23:22
  • Be that as it may, SO is not a tutorial or code writing service. Once you have a specific, programming question, it will be appropriate here. – user3483203 Jun 06 '18 at 23:23
  • Is there any specific name for the graph you have posted? – Ajax1234 Jun 06 '18 at 23:25
  • 2
    In principle the whole graph should be doable using [annotations](https://matplotlib.org/tutorials/text/annotations.html) and [`Rectangle`](https://matplotlib.org/gallery/shapes_and_collections/artist_reference.html)s. But you must be very lucky if you find someone writing that code for you without stating any clear and specific problem here. – ImportanceOfBeingErnest Jun 06 '18 at 23:30
  • I think Parallel coordinates graph is something similar but not sure whether it exactly like this or not :( – muazfaiz Jun 06 '18 at 23:37
  • 2
    If you start from this question you may be able to either solve the problem or get to a more specific question: https://stackoverflow.com/questions/49760882/python-create-word-plot-between-two-lists-in-matplotlib-to-show-list-commonality – OriolAbril Jun 07 '18 at 01:10

0 Answers0