def plot_hl_write(path): scan_modes = ["balanced"] frames = [] for mode in scan_modes: frame = util.process_folder( path, filter_scan_mode=mode, filter_benchmark="gatt") frames.append(frame) all_frames = pd.concat(frames) # util.print_full(all_frames.groupby(['Operation', 'Connection Interval # (s)', 'Phone Model']).mean()) # util.print_full(all_frames.groupby(['Operation', 'Connection Interval # (s)', 'Phone Model']).median()) all_frames["Phone Model"] = all_frames["Phone Model"].astype("category") # all_frames = all_frames[all_frames["Connection Interval (s)"] == 0.32] print all_frames means = all_frames.groupby( ["Phone Model", "Operation", "Connection Interval (s)"], as_index=False).mean() means = means[means["Operation"] != "Read"] print means sums = means.groupby(["Phone Model"], as_index=False).sum() print sums fig, ax1 = plt.subplots() wifion_20ms_write = all_frames[(all_frames['Operation'] == 'Write Sum') & ( all_frames['Connection Interval (s)'] == 0.02) & (all_frames['WiFi State'] == 'on')] print wifion_20ms_write sns.barplot(x="Time (s)", y="Phone Model", data=wifion_20ms_write, ax=ax1) ax1.set_ylabel('') ax1.set_xlabel('Mean Time (s)') return fig, ax1
def plot_rssi(): path = "../data/rssi" df = util.process_folder(path, filter_benchmark='rssi') df = df[(df['RSSI (dBm)'] < 0)] df["Phone Model"] = df["Phone Model"].astype("category") util.set_style(font_scale=1.7) util.set_colors() # figure 2a fig, axarr = plt.subplots(1, 2, sharey='row', figsize=(12, 5.5)) models = [ 'Samsung Galaxy S3', 'LG Nexus 5X', 'Motorola Nexus 6', 'HTC One M9', 'Motorola MotoE2', 'Motorola Moto G', 'LG Nexus 4', 'Asus Nexus 7', 'LG Nexus 5', 'LG G3' ] models = models[::-1] sns.pointplot(x="RSSI (dBm)", y="Phone Model", order=models, hue="Time of Day", hue_order=['Morning', 'Noon', 'Afternoon', 'Night'], markers=['*', '^', '.', 'x'], data=df[(df['Distance (m)'] == 1.0)], join=False, ci=None, ax=axarr[0]) # , size=10, aspect=2.0, legend=False) # Now add the legend with some customizations. axarr[0].legend(loc='best', frameon=True, framealpha=1, edgecolor='0', fontsize=14) axarr[0].set_title("Distance = 1 m", fontweight="bold") axarr[0].set_ylabel('') axarr[0].set_xlabel('RSSI (dBm)') axarr[0].set_xlim(-110, -50) sns.pointplot(x="RSSI (dBm)", y="Phone Model", order=models, hue="Time of Day", hue_order=['Morning', 'Noon', 'Afternoon', 'Night'], markers=['*', '^', '.', 'x'], data=df[(df['Distance (m)'] == 10.0)], join=False, ci=None, ax=axarr[1]) # , size=10, aspect=2.0, legend=False) # Now add the legend with some customizations. axarr[1].legend_.remove() # (frameon=True, framealpha=1, edgecolor='0') axarr[1].set_title("Distance = 10 m", fontweight="bold") axarr[1].set_ylabel('') axarr[1].set_xlabel('RSSI (dBm)') axarr[1].set_xlim(-110, -50) fig.tight_layout() if not os.path.exists(SAVEPATH): os.makedirs(SAVEPATH) fig.savefig(SAVEPATH + 'rssi_distance_time.pdf')
def get_df(path): scan_modes = ["balanced"] frames = [] for mode in scan_modes: frame = util.process_folder(path, filter_scan_mode=mode, filter_benchmark="gatt") frames.append(frame) all_frames = pd.concat(frames) return all_frames
def plot_hl_latency(path): fig, ax1 = plt.subplots() scan_modes = ["balanced"] frames = [] for mode in scan_modes: frame = util.process_folder(path, filter_scan_mode=mode, filter_replicas=None, filter_benchmark='first') frames.append(frame) all_frames = pd.concat(frames) # TODO this does not work dependent on pandas version.. all_frames["Advertising Interval (ms)"] = all_frames[ "Advertising Interval (ms)"].astype('category') all_frames["Phone Model"] = all_frames["Phone Model"].astype("category") all_frames = all_frames.rename( columns={'OS Timestamp (ms)': 'OS Timestamp (s)'}) all_frames["OS Timestamp (s)"] = all_frames["OS Timestamp (s)"] / 1000.0 all_frames = all_frames[(all_frames['Advertising Interval (ms)'] == 1280)] sns.barplot(y="Phone Model", x="OS Timestamp (s)", data=all_frames, ax=ax1) ax1.set_ylabel("") ax1.set_xlabel('Mean Time (s)') return fig, ax1
def plot_rssi(): # get dataframe for RSSI path_rssi = "../data/rssi" df_rssi = util.process_folder(path_rssi, filter_benchmark='rssi') # df_rssi["Phone Model"] = df_rssi["Phone Model"].astype("category") df_rssi = df_rssi[(df_rssi['RSSI (dBm)'] < 0)] id_map = {} # {phone model: [next_id, {old id : new id}}] # add phone id df_rssi = df_rssi[(df_rssi["Phone Model"].isin( ["Asus Nexus 7", "LG Nexus 5", "Motorola MotoE2", "Motorola Nexus 6"])) & (df_rssi['Device ID'] != 'unknown')] df_rssi['Phone ID'] = "" df_rssi.index = range(len(df_rssi)) for index, row in df_rssi.iterrows(): model = row['Phone Model'] if model not in id_map: id_map[model] = [1, {}] device = row['Device ID'] if device not in id_map[model][1]: id_map[model][1][device] = "Phone " + str(id_map[model][0]) id_map[model][0] += 1 df_rssi.set_value(index, 'Phone ID', id_map[model][1][device]) # get dataframe for latency path_latency = "../data/soc/adv-prr-latency/1280ms" df_latency = util.process_folder(path_latency, filter_scan_mode="balanced", filter_replicas=None, filter_benchmark='first') # df_latency["Phone Model"] = df_latency["Phone Model"].astype("category") df_latency = df_latency.rename( columns={'OS Timestamp (ms)': 'OS Timestamp (s)'}) df_latency["OS Timestamp (s)"] = df_latency["OS Timestamp (s)"] / 1000.0 # add phone id df_latency = df_latency[(df_latency["Phone Model"].isin( ["Asus Nexus 7", "LG Nexus 5", "Motorola MotoE2", "Motorola Nexus 6"])) & (df_latency['Device ID'] != 'unknown')] df_latency['Phone ID'] = "" df_latency.index = range(len(df_latency)) for index, row in df_latency.iterrows(): model = row['Phone Model'] if model not in id_map: id_map[model] = [1, {}] device = row['Device ID'] if device not in id_map[model][1]: id_map[model][1][device] = "Phone " + str(id_map[model][0]) id_map[model][0] += 1 df_latency.set_value(index, 'Phone ID', id_map[model][1][device]) print df_rssi["Phone Model"].unique() print df_latency["Phone Model"].unique() print id_map # figure 12 # sns.set_context("paper") # sns.set(style="whitegrid", font_scale=1.5) fig, axarr = plt.subplots(1, 2, sharey='row', figsize=(10, 4)) # fig.subplots_adjust(wspace=0, hspace=0) print df_rssi[(df_rssi['Distance (m)'] == 1.0)] hue_order = sorted(df_rssi['Phone ID'].unique()) df_rssi["Phone Model"] = df_rssi["Phone Model"].astype("category") sns.boxplot(x="RSSI (dBm)", y="Phone Model", data=df_rssi[(df_rssi['Distance (m)'] == 1.0)], hue="Phone ID", hue_order=hue_order, ax=axarr[0]) # , size=10, aspect=2.0, legend=False) # Now add the legend with some customizations. axarr[0].legend_.remove() # (frameon=True, framealpha=1, edgecolor='0') axarr[0].set_title("Distance = 1 m", fontweight="bold") axarr[0].set_ylabel('') axarr[0].set_xlabel('RSSI (dBm)') axarr[0].set_xlim(-110, -50) df_latency["Phone Model"] = df_latency["Phone Model"].astype("category") sns.boxplot(x="OS Timestamp (s)", y="Phone Model", data=df_latency, hue="Phone ID", hue_order=hue_order, ax=axarr[1]) # , size=10, aspect=2.0, legend=False) # Now add the legend with some customizations. axarr[1].legend_.remove() # (frameon=True, framealpha=1, edgecolor='0') axarr[1].set_title("Scan Mode = balanced", fontweight="bold") axarr[1].set_ylabel('') axarr[1].set_xlabel('OS Timestamp (s)') # axarr[1].set_xlim(-110, ) fig.tight_layout() if not os.path.exists(SAVEPATH): os.makedirs(SAVEPATH) fig.savefig(SAVEPATH + 'between_model.pdf')
def plot_rssi(): path = "../data/rssi" df = util.process_folder(path, filter_benchmark='rssi') # df = df[(df["Phone Model"] == "Motorola MotoE2")] df = df[(df['RSSI (dBm)'] < 0)] df["Phone Model"] = df["Phone Model"].astype("category") d = get_distances(df["RSSI (dBm)"]) df["Estimated Distance (m)"] = d df = df[(df['Distance (m)'] == 1.0) | (df['Distance (m)'] == 05.0) | (df['Distance (m)'] == 10.0) | (df['Distance (m)'] == 20.0)] # # figure 6 all distances # plt.figure(figsize=(10, 4)) # g = sns.pointplot(x="Distance (m)", y="RSSI (dBm)", hue="Phone Model", markers=['.','v','^','<','>','*','s','h','+','d'], data=df, ci=None) #, size=10, aspect=2.0, legend=False) # # Now add the legend with some customizations. # #plt.legend(bbox_to_anchor=(0.45, -0.1), loc="upper center", ncol=4) # #ax.set_title("Distance = 1 m", fontweight="bold") # plt.ylabel('RSSI (dBm)') # plt.xlabel('Distance (m)') # # # ref: http://stackoverflow.com/a/10154763/1843698 # handles, labels = plt.gca().get_legend_handles_labels() # lgd = plt.legend(handles, labels, loc='upper center', bbox_to_anchor=(0.45,-0.2), ncol=5, fontsize=10) # g.get_figure().savefig(SAVEPATH+'rssi-line-distance.pdf', bbox_extra_artists=(lgd,), bbox_inches='tight') # figure 1b 4 distances plt.figure(figsize=(10, 5)) markers = ['p', 'v', '^', '<', '>', '*', 's', 'h', 'P', 'd'] linestyles = ['-', '--', '-.', ':'] models = [ 'Asus Nexus 7', 'HTC One M9', 'LG G3', 'LG Nexus 4', 'LG Nexus 5', 'LG Nexus 5X', 'Motorola Moto G', 'Motorola MotoE2', 'Motorola Nexus 6', 'Samsung Galaxy S3' ] for i in range(len(models)): m = models[i] df_sub = df[(df['Phone Model'] == m)] grouped = df_sub.groupby('Distance (m)')['RSSI (dBm)'].mean() print m print markers[i] grouped.plot(x='Distance (m)', y="RSSI (dBm)", marker=markers[i], linestyle=linestyles[i % len(linestyles)], label=m) # , size=10, aspect=2.0, legend=False) # Now add the legend with some customizations. # plt.legend(bbox_to_anchor=(0.45, -0.1), loc="upper center", ncol=4) # ax.set_title("Distance = 1 m", fontweight="bold") plt.ylabel('RSSI (dBm)') plt.xlabel('Distance (m)') plt.xlim(0, 21) # ref: http://stackoverflow.com/a/10154763/1843698 handles, labels = plt.gca().get_legend_handles_labels() lgd = plt.legend(handles, labels, loc='center right', bbox_to_anchor=(1.43, 0.5)) if not os.path.exists(SAVEPATH): os.makedirs(SAVEPATH) plt.savefig(SAVEPATH + 'rssi_vs_true_dist.pdf', bbox_extra_artists=(lgd, ), bbox_inches='tight')
def plot_prr(path): frames = [] for path in paths: frame = util.process_folder(path, filter_replicas=1, filter_benchmark="prr") frames.append(frame) all_frames = pd.concat(frames) all_frames["Advertising Interval (ms)"] = \ all_frames["Advertising Interval (ms)"].astype('category') all_frames["Phone Model"] = all_frames["Phone Model"].astype('category') all_frames["SoC"] = all_frames["SoC"].astype('category') all_frames["API Version"] = all_frames["API Version"].astype('category') all_frames["WiFi State"] = all_frames["WiFi State"].astype('category') all_frames = all_frames[(all_frames["Advertising Interval (ms)"] == 160)] all_frames = all_frames[(all_frames["Scan Mode"] == "balanced")] wifi_idle = all_frames[(all_frames["WiFi State"] == "on")] nexus5 = wifi_idle[(wifi_idle["Phone Model"] == "LG Nexus 5")] nexus6 = wifi_idle[(wifi_idle["Phone Model"] == "Motorola Nexus 6")] nexus7 = wifi_idle[(wifi_idle["Phone Model"] == "Asus Nexus 7")] fig, axarr = plt.subplots(1, 3, sharey=True) fig.subplots_adjust(wspace=0, hspace=0) sns.barplot(x='PRR (%)', y="API Version", data=nexus7, ax=axarr[0]) axarr[0].set_title("Asus Nexus 7", fontweight="bold") axarr[0].set_xlabel('Mean PRR (%)') axarr[0].set_ylabel('API Version') axarr[0].set_xlim(0, 100) print "\n" # add numbers on top of bars for p in axarr[0].patches: print "width: ", p.get_width() print "y: ", p.get_y() if math.isnan(p.get_width()): axarr[0].annotate('Not Available', (10, p.get_y() + 0.5)) else: axarr[0].annotate('%.2f' % p.get_width(), (p.get_width() + 5, p.get_y() + 0.5)) sns.barplot(x='PRR (%)', y="API Version", data=nexus5, ax=axarr[1]) axarr[1].set_title("LG Nexus 5", fontweight="bold") axarr[1].set_ylabel('') axarr[1].set_xlabel('Mean PRR (%)') axarr[1].set_xlim(0, 100) print "\n" # add numbers on top of bars for p in axarr[1].patches: print "width: ", p.get_width() print "y: ", p.get_y() if math.isnan(p.get_width()): axarr[1].annotate('Not Available', (10, p.get_y() + 0.5)) sns.barplot(x='PRR (%)', y="API Version", data=nexus6, ax=axarr[2]) axarr[2].set_title("Motorola Nexus 6", fontweight="bold") axarr[2].set_ylabel('') axarr[2].set_xlabel('Mean PRR (%)') axarr[2].set_xlim(0, 100) print "\n" # add numbers on top of bars for p in axarr[2].patches: print "width: ", p.get_width() print "y: ", p.get_y() if math.isnan(p.get_width()): axarr[2].annotate('Not Available', (10, p.get_y() + 0.5)) # else: # axarr[2].annotate('%.2f' % p.get_width(), (p.get_width() + 5, p.get_y()+0.5)) return fig, axarr
def plot_latency(path): fig, ax1 = plt.subplots() scan_modes = ["low_latency"] frames = [] for mode in scan_modes: frame = util.process_folder(path, filter_scan_mode=mode, filter_replicas=None, filter_benchmark='first') frames.append(frame) all_frames = pd.concat(frames) # TODO this does not work dependent on pandas version.. all_frames["Advertising Interval (ms)"] = all_frames[ "Advertising Interval (ms)"].astype('category') all_frames["Phone Model"] = all_frames["Phone Model"].astype("category") all_frames["SoC"] = all_frames["SoC"].astype('category') all_frames = all_frames.rename( columns={'OS Timestamp (ms)': 'OS Timestamp (s)'}) all_frames["OS Timestamp (s)"] = all_frames["OS Timestamp (s)"] / 1000.0 all_frames = all_frames[(all_frames['Advertising Interval (ms)'] == 1280)] df = all_frames soc_list = df["SoC"].unique() colors = sns.color_palette("colorblind", len(soc_list)) color_dict = dict(zip(soc_list, colors)) tmp = df.drop_duplicates("Phone Model") tmp["color"] = tmp["SoC"].map(color_dict) soc_palette = dict(zip(tmp["Phone Model"], tmp["color"])) models = [ 'Samsung Galaxy S3', 'LG Nexus 5X', 'Motorola Nexus 6', 'HTC One M9', 'Motorola MotoE2', 'Motorola Moto G', 'LG Nexus 4', 'Asus Nexus 7', 'LG Nexus 5', 'LG G3' ] models = models[::-1] ax = sns.boxplot(y="Phone Model", x="OS Timestamp (s)", palette=soc_palette, order=models, data=all_frames, ax=ax1) ax1.set_ylabel('') boxes = ax.artists grouped = all_frames.groupby('Phone Model') socs = grouped['SoC'].agg(lambda x: x.value_counts().index[0]) socs_set = socs.unique() socs_plot = [socs.loc[m] for m in models] hatches = ('/', '+', 'x', '\\', '|', 'o') boxs_legend = [] socs_legend = [] for i, box in enumerate(boxes): soc_index = socs_set.tolist().index(socs_plot[i]) print soc_index # Set a different hatch for each box box.set_edgecolor('k') box.set_hatch(3 * hatches[soc_index]) box.set_facecolor(colors[soc_index]) if socs_plot[i] not in socs_legend: boxs_legend.append(box) socs_legend.append(socs_plot[i]) socs_legend, boxs_legend = zip(*sorted(zip(socs_legend, boxs_legend))) ax.legend(boxs_legend, socs_legend, loc='center right', bbox_to_anchor=(1.35, 0.5)) return fig, ax1
def plot_rssi(): path = "../data/rssi" df = util.process_folder(path, filter_benchmark='rssi') # df = df[(df["Phone Model"] == "Motorola MotoE2")] # sns.set_context("paper") df = df[(df['RSSI (dBm)'] < 0)] # sns.set_context("paper") # sns.set_style("whitegrid") df["Phone Model"] = df["Phone Model"].astype("category") # sns.set(style="whitegrid", font_scale=1) util.set_style(font_scale=1.7) util.set_colors() # figure 2b fig, axarr = plt.subplots(1, 2, sharey='row', figsize=(12, 5.5)) # fig.subplots_adjust(wspace=0, hspace=0) models = [ 'Samsung Galaxy S3', 'LG Nexus 5X', 'Motorola Nexus 6', 'HTC One M9', 'Motorola MotoE2', 'Motorola Moto G', 'LG Nexus 4', 'Asus Nexus 7', 'LG Nexus 5', 'LG G3' ] models = models[::-1] grouped = df.groupby('Phone Model') socs = grouped['SoC'].agg(lambda x: x.value_counts().index[0]) socs_set = socs.unique() socs_plot = [socs.loc[m] for m in models] hatches = ('/', '+', 'x', '\\', '|', 'o') colors = sns.color_palette("colorblind", len(socs_set)) ax = sns.boxplot(x="RSSI (dBm)", y="Phone Model", data=df[(df['Distance (m)'] == 1.0)], order=models, ax=axarr[0]) # , size=10, aspect=2.0, legend=False) # Now add the legend with some customizations. # axarr[0].legend(frameon=True, framealpha=1, edgecolor='0') axarr[0].set_title("Distance = 1 m", fontweight="bold") axarr[0].set_ylabel('') axarr[0].set_xlabel('RSSI (dBm)') axarr[0].set_xlim(-110, -50) for i, box in enumerate(ax.artists): soc_index = socs_set.tolist().index(socs_plot[i]) # Set a different hatch for each box box.set_edgecolor('k') box.set_hatch(3 * hatches[soc_index]) box.set_facecolor(colors[soc_index]) ax = sns.boxplot(x="RSSI (dBm)", y="Phone Model", data=df[(df['Distance (m)'] == 10.0)], order=models, ax=axarr[1]) # , size=10, aspect=2.0, legend=False) # Now add the legend with some customizations. # axarr[1].legend(frameon=True, framealpha=1, edgecolor='0') axarr[1].set_title("Distance = 10 m", fontweight="bold") axarr[1].set_ylabel('') axarr[1].set_xlabel('RSSI (dBm)') axarr[1].set_xlim(-110, -50) boxs_legend = [] socs_legend = [] for i, box in enumerate(ax.artists): soc_index = socs_set.tolist().index(socs_plot[i]) # Set a different hatch for each box box.set_edgecolor('k') box.set_hatch(3 * hatches[soc_index]) box.set_facecolor(colors[soc_index]) if socs_plot[i] not in socs_legend: boxs_legend.append(box) socs_legend.append(socs_plot[i]) socs_legend, boxs_legend = zip(*sorted(zip(socs_legend, boxs_legend))) ax.legend(boxs_legend, socs_legend, loc='best', frameon=True, framealpha=1, edgecolor='0', fontsize=14) # , bbox_to_anchor = (1.35, 0.5)) fig.tight_layout() if not os.path.exists(SAVEPATH): os.makedirs(SAVEPATH) fig.savefig(SAVEPATH + 'rssi_distance_boxplot.pdf')
def plot_prr(path): # scan_modes = ["low_power", "balanced","low_latency"] scan_modes = ["balanced"] frames = [] for mode in scan_modes: frame = util.process_folder(path, filter_scan_mode=mode, filter_replicas=1, filter_benchmark="prr") frames.append(frame) all_frames = pd.concat(frames) all_frames["Advertising Interval (ms)"] = all_frames[ "Advertising Interval (ms)"].astype('category') all_frames["Phone Model"] = all_frames["Phone Model"].astype('category') all_frames["SoC"] = all_frames["SoC"].astype('category') # hard code models so same chips stay together models = [ 'Samsung Galaxy S3', 'LG Nexus 5X', 'Motorola Nexus 6', 'HTC One M9', 'Motorola MotoE2', 'Motorola Moto G', 'LG Nexus 4', 'Asus Nexus 7', 'LG Nexus 5', 'LG G3' ] pos = np.arange(len(models)) + .5 grouped = all_frames.groupby('Phone Model') vals = grouped['PRR (%)'].agg([np.mean, np.std]) socs = grouped['SoC'].agg(lambda x: x.value_counts().index[0]) socs_set = socs.unique() print socs vals_plot = [vals.loc[m, 'mean'] for m in models] errs_plot = [vals.loc[m, 'std'] for m in models] socs_plot = [socs.loc[m] for m in models] print vals_plot print errs_plot # get palette colors = sns.color_palette("colorblind", len(socs_set)) # get patterns patterns = ('-', '+', 'x', '\\', '|', 'o', 'O', '.') fig, ax = plt.subplots(1) fig.subplots_adjust(wspace=0, hspace=0) bars = plt.barh(pos, vals_plot, xerr=errs_plot, align='center', edgecolor='k') bars_legend = [] socs_legend = [] for i in range(len(bars)): soc_index = socs_set.tolist().index(socs_plot[i]) pattern = 3 * patterns[soc_index] color = colors[soc_index] bars[i].set_hatch(pattern) bars[i].set_facecolor(color) if socs_plot[i] not in socs_legend: bars_legend.append(bars[i]) socs_legend.append(socs_plot[i]) plt.yticks(pos, models) socs_legend, bars_legend = zip(*sorted(zip(socs_legend, bars_legend))) plt.legend(bars_legend, socs_legend, loc="upper right", frameon=True, framealpha=1, edgecolor='0') # bbox_to_anchor = (1.37, 0.8)) # ax.set_title("Scan Mode = balanced", fontweight="bold") ax.set_ylabel('') ax.set_xlabel('Mean PRR (%)') ax.set_xlim(0, 100) return fig, ax
def plot_prr(path): frames = [] for path in paths: frame = util.process_folder(path, filter_replicas=1, filter_benchmark="prr") frames.append(frame) all_frames = pd.concat(frames) print all_frames all_frames["Advertising Interval (ms)"] = \ all_frames["Advertising Interval (ms)"].astype('category') all_frames["Phone Model"] = all_frames["Phone Model"].astype('category') all_frames["SoC"] = all_frames["SoC"].astype('category') all_frames["WiFi State"] = all_frames["WiFi State"].astype('category') all_frames = all_frames[(all_frames["Advertising Interval (ms)"] == 160)] all_frames = all_frames[(all_frames["Scan Mode"] == "balanced")] wifion = all_frames[(all_frames["WiFi State"] == "on")] print wifion wifiactive = all_frames[(all_frames["WiFi State"] == "active")] print wifiactive fig, axarr = plt.subplots(1, 2, sharey='row', figsize=(10, 4)) # fig.subplots_adjust(wspace=0, hspace=0) models = [ 'Samsung Galaxy S3', 'LG Nexus 5X', 'Motorola Nexus 6', 'HTC One M9', 'Motorola MotoE2', 'Motorola Moto G', 'LG Nexus 4', 'Asus Nexus 7', 'LG Nexus 5', 'LG G3' ] models = models[::-1] bars = sns.barplot(x='PRR (%)', y="Phone Model", data=wifion, order=models, ax=axarr[0]) # axarr[0].legend_.remove() #(frameon=True, framealpha=1, edgecolor='0') axarr[0].set_title("WiFi Idle", fontweight="bold") axarr[0].set_ylabel('') axarr[0].set_xlabel('Mean PRR (%)') axarr[0].set_xlim(0, 100) grouped = wifion.groupby('Phone Model') socs = grouped['SoC'].agg(lambda x: x.value_counts().index[0]) socs_set = socs.unique() socs_plot = [socs.loc[m] for m in models] hatches = ('/', '+', 'x', '\\', '|', 'o') colors = sns.color_palette("colorblind", len(socs_set)) bars_legend = [] socs_legend = [] for i, bar in enumerate(bars.patches): soc_index = socs_set.tolist().index(socs_plot[i]) # Set a different hatch for each bar bar.set_edgecolor('k') bar.set_hatch(3 * hatches[soc_index]) bar.set_facecolor(colors[soc_index]) if socs_plot[i] not in socs_legend: bars_legend.append(bar) socs_legend.append(socs_plot[i]) # socs_legend, bars_legend = zip(*sorted(zip(socs_legend, bars_legend))) # axarr[0].legend(bars_legend, socs_legend, loc='center right', frameon=True, framealpha=1, edgecolor='0') bars = sns.barplot(x='PRR (%)', y="Phone Model", data=wifiactive, order=models, ax=axarr[1]) axarr[1].set_title("WiFi Active", fontweight="bold") axarr[1].set_ylabel('') axarr[1].set_xlabel('Mean PRR (%)') axarr[1].set_xlim(0, 100) bars_legend = [] socs_legend = [] for i, bar in enumerate(bars.patches): soc_index = socs_set.tolist().index(socs_plot[i]) # Set a different hatch for each bar bar.set_edgecolor('k') bar.set_hatch(3 * hatches[soc_index]) bar.set_facecolor(colors[soc_index]) if socs_plot[i] not in socs_legend: bars_legend.append(bar) socs_legend.append(socs_plot[i]) socs_legend, bars_legend = zip(*sorted(zip(socs_legend, bars_legend))) axarr[1].legend(bars_legend, socs_legend, loc='center right', frameon=True, framealpha=1, edgecolor='0') return fig, axarr