2

My intention is to re-create the below graph using matplotlib and seaborn:

enter image description here

The problem is that, The way I'm doing it I only get the graphs for Mediation. My current graph is shown below:

enter image description here

my code is shown below:

def save_bar_chart(title):
    filename = "response_time_summary_" + str(message_size) + "_" + str(backend_delay) + "ms.png"
    print("Creating chart: " + title + ", File name: " + filename)
    fig, ax = plt.subplots()
    fig.set_size_inches(11, 8)

    df_results = df.loc[(df['Message Size (Bytes)'] == message_size) & (df['Back-end Service Delay (ms)'] == backend_delay)]

    df_results = df_results[
        ['Message Size (Bytes)', 'Concurrent Users', '90th Percentile of Response Time (ms)', '95th Percentile of Response Time (ms)',
         '99th Percentile of Response Time (ms)']]

    df_results = df_results.set_index(['Message Size (Bytes)', 'Concurrent Users']).stack().reset_index().rename(
        columns={'level_2': 'Summary', 0: 'Response Time (ms)'})

    sns.barplot(x='Concurrent Users', y='Response Time (ms)', hue='Summary', data=df_results, ci=None)
    ax.yaxis.set_major_formatter(tkr.FuncFormatter(lambda y, p: "{:,}".format(y)))
    plt.suptitle(title)
    plt.legend(loc=2, frameon=True, title="Response Time Summary")
    plt.show()
    plt.savefig(filename)
    plt.clf()
    plt.close(fig)

The data looks like this:

enter image description here

This link contains the data

Suleka_28
  • 2,761
  • 4
  • 27
  • 43

2 Answers2

0

You can reshape your DataFrame using melt

df_ = df[['Concurrent Users', '90th Percentile of Response Time (ms)',
     '95th Percentile of Response Time (ms)', '98th Percentile of Response Time (ms)',
     '99th Percentile of Response Time (ms)', '99.9th Percentile of Response Time (ms)']].melt('Concurrent Users')

and use the hue parameter in barplot

fig, ax = plt.subplots()
sns.barplot(x='Concurrent Users', y='value', hue=0, data=df_, ax=ax)

The new DataFrame df_ looks like this:

   Concurrent Users                                      0  value
0                50  90th Percentile of Response Time (ms)     26
1               100  90th Percentile of Response Time (ms)     51
2               200  90th Percentile of Response Time (ms)    105
3               300  90th Percentile of Response Time (ms)    158
4               500  90th Percentile of Response Time (ms)    243

And has these dtypes

Concurrent Users     int64
0                   object
value                int64
JoergVanAken
  • 1,286
  • 9
  • 10
0

You can try this:

df_out = df.set_index(['Concurrent Users','Scenario Name']).filter(like='Percentile').unstack()
df_out.columns = [f'{i} - {j}' for i, j in df_out.columns]
df_out.plot.bar(figsize=(15,10))

Output:

enter image description here

Scott Boston
  • 147,308
  • 15
  • 139
  • 187