0

I have a data structure that is a nested dictionary called team_dict. Team_dict looks like this: team_dict[teams][players][stats].

Team_dict = {'gs': {'Steph': {'PPG':26 ,'Reb':10 'Ast':10} }}

The problem I am having is that I can plot all of my data fine but i want to get the markers to be the same color for each team. I know that the reason is because i is iterated over the loop for each player. Right now my code for the scatter plot is:

'data': [
    go.Scatter(
        x=[team_dict[i][p]['Salary']],
        y=[team_dict[i][p]['PPG']],
        text=p,
        mode='markers',
        opacity=0.7,
        marker={
            'size': 15,
            'line': {'width': .5, 'color': 'black'}
        },
        name= i,
    )
     for i in team_initials
         for p in team_dict[i]

],

Here is an image of how it looks like now: scatterplot so far I have tried looking at the dash documentation and other methods but nothing seems to work. Am I not supposed to use nested dictionaries to plot dash graphs?

lwileczek
  • 2,084
  • 18
  • 27
WoonBoon
  • 3
  • 1

1 Answers1

1

create a dictionary for each team like:

team_colors = {'gs':'#E90', 'hou': '#555', 'LAC': '#FF0'}

then when you iterate add color to your scatter plot by calling the color attribute in marker.

'data': [
    go.Scatter(
        x=[team_dict[i][p]['Salary']],
        y=[team_dict[i][p]['PPG']],
        text=p,
        mode='markers',
        opacity=0.7,
        marker={
            'size': 15,
            'line': {'width': .5, 'color': 'black'},
            'color':team_color[i]  # looks like you iterate through team names
        },
        name= i,
    )
     for i in team_initials
         for p in team_dict[i]

],

And that should make the plays on the same team have the same color. It mike be better to turn your nested dictionary into a pandas data frame and pass a whole team at a time and just call the columns you want "Salary" and "PPG". You can use this post to show you how to make a dataframe from your nested dictionary.

lwileczek
  • 2,084
  • 18
  • 27
  • thanks! I actually figured out that i could have just done x=[team_dict[i][s]['Salary'] for s in team_dict[i]] but i'll follow up on making it into a pandas data frame. – WoonBoon Jul 16 '18 at 05:02