How do I add category names to my seaborn boxplot when my data is from a python dictionary?
Question: I have some data that is sitting in a python dictionary of lists.

How can I use the keys from the dictionary as category labels for this
boxplot? Here is a sample of the dictionary, plot_data:

    
    
    plot_data {
        'Group1': [0.02339976, 0.03235323, 0.12835462, 0.10238375, 0.04223188],
        'Group2': [0.02339976, 0.03235323, 0.12835462, 0.10238375, 0.04223188]
    }
    

This code is probably a mess, but here it is:

    
    
    data = plot_data.values()
    
    #Get data in proper format
    fixed_data = list(sorted(data))
    
    
    #Set up the graph parameters
    sns.set(context='notebook', style='whitegrid')
    sns.axlabel(xlabel="Groups", ylabel="Y-Axis", fontsize=16)
    
    
    #Plot the graph
    sns.boxplot(data=fixed_data, whis=np.inf, width=.18)
    sns.swarmplot(data=fixed_data, size=6, edgecolor="black", linewidth=.9)
    

[![Boxplot with no category
labels](http://i.stack.imgur.com/RzLiE.png)](http://i.stack.imgur.com/RzLiE.png)


Answer: Here how to add category labels "manually":

    
    
    import seaborn as sns, matplotlib.pyplot as plt, operator as op
    
    plot_data = {
      'Group1': range(10,16),
      'Group2': range(5,15),
      'Group3': range(1,5)
    }
    
    # sort keys and values together
    sorted_keys, sorted_vals = zip(*sorted(plot_data.items(), key=op.itemgetter(1)))
    
    # almost verbatim from question
    sns.set(context='notebook', style='whitegrid')
    sns.axlabel(xlabel="Groups", ylabel="Y-Axis", fontsize=16)
    sns.boxplot(data=sorted_vals, width=.18)
    sns.swarmplot(data=sorted_vals, size=6, edgecolor="black", linewidth=.9)
    
    # category labels
    plt.xticks(plt.xticks()[0], sorted_keys)
    
    plt.show()
    

And here the output:
[![output](http://i.stack.imgur.com/xN3Vz.png)](http://i.stack.imgur.com/xN3Vz.png)

