How to plot multi column categorical bar chart using seaborn?

后端 未结 1 784
借酒劲吻你
借酒劲吻你 2021-01-27 20:02

I have a data frame as shown below:

I want to structure it in a way that I will be able to plot a bar chart as shown below:

The data is here.

相关标签:
1条回答
  • 2021-01-27 20:36

    You want to melt and then use a barplot with hue:

    import seaborn as sns
    
    small_data = df_results[[ 'Scenario Name','Concurrent Users', '90th Percentile of Response Time (ms)', 
                     '95th Percentile of Response Time (ms)','99th Percentile of Response Time (ms)']]
    small_data = small_data.melt(id_vars=['Scenario Name', 'Concurrent Users'])
    small_data['new_var'] = small_data.variable + ' - ' + small_data['Scenario Name']
    
    g = sns.barplot(x="Concurrent Users", y="value", hue='new_var', data=small_data)
    sns.set(rc={'figure.figsize':(11,8)})
    

    Output:

    To save use

    fig = g.get_figure()
    fig.savefig(filename)
    

    And just wrap all that in a function.

    0 讨论(0)
提交回复
热议问题