我希望以一种能够绘制如下所示的条形图的方式来构造它:
数据为here。
注意:Echo API数据=中介数据
我现有的代码如下所示,我不知道如何进行。非常感谢您的帮助。
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[
[ 'Scenario Name','Concurrent Users', '90th Percentile of Response Time (ms)', '95th Percentile of Response Time (ms)',
'99th Percentile of Response Time (ms)']]
答案 0 :(得分:2)
您想先melt
,然后使用带有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)})
输出:
要保存使用
fig = g.get_figure()
fig.savefig(filename)
然后将所有内容包装在一个函数中。