Skip to content

Commit

Permalink
Added argument to omit line plots
Browse files Browse the repository at this point in the history
  • Loading branch information
tinstructor committed Jan 10, 2020
1 parent e2a49b0 commit 2479524
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions examples/interference/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import glob
import os
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--noline", action="store_true", help="Omit line plot generation")
args = parser.parse_args()

file_list = []
script_dir = os.path.dirname(__file__)
Expand Down Expand Up @@ -95,22 +100,25 @@
plt.savefig(if_phy + "_" + payload_size + "_" + sir + ".png")
plt.close()

styles = ['s-', 'o-', '^-', 'x-', 'd-', 'h-']
# NOTE loops over each (if_phy, payload_size, offset) tuple in line_info
for if_phy, payload_size, offset in line_info:
title = "Interference: " + if_phy + ", Payload: " + payload_size + ", Offset: " + offset
# NOTE sort (alfabetically) by sir
line_info[if_phy, payload_size, offset] = dict(sorted(line_info[if_phy, payload_size, offset].items(), key=lambda x: x[0].lower()))
# NOTE first transpose the dataframe (i.e., reflect the dataframe over its main
# diagonal by writing rows as columns and vice-versa) and plot it as a line plot
df = pd.DataFrame(line_info[if_phy, payload_size, offset]).T
ax = df.plot(kind='line', figsize=(10,7), style=styles, xticks=range(len(list(df.index.values))))
ax.legend(loc='lower right')
ax.set_xlabel('SIR between TX and IF')
ax.set_ylabel('Packet Reception Rate [%]')
ax.set_ylim([0, 120])
ax.set_yticks([0,20,40,60,80,100])
ax.set_xlim([-0.05,len(list(df.index.values)) - 0.95])
plt.title(title)
plt.savefig(if_phy + "_" + payload_size + "_" + offset + ".png")
plt.close()
if not args.noline:
styles = ['s-', 'o-', '^-', 'x-', 'd-', 'h-']
# NOTE loops over each (if_phy, payload_size, offset) tuple in line_info
for if_phy, payload_size, offset in line_info:
title = "Interference: " + if_phy + ", Payload: " + payload_size + ", Offset: " + offset
# NOTE sort (alfabetically) by sir
line_info[if_phy, payload_size, offset] = dict(sorted(line_info[if_phy, payload_size, offset].items(), key=lambda x: x[0].lower()))
# NOTE first transpose the dataframe (i.e., reflect the dataframe over its main
# diagonal by writing rows as columns and vice-versa) and plot it as a line plot
df = pd.DataFrame(line_info[if_phy, payload_size, offset]).T
ax = df.plot(kind='line', figsize=(10,7), style=styles, xticks=range(len(list(df.index.values))))
ax.legend(loc='lower right')
ax.set_xlabel('SIR between TX and IF')
ax.set_ylabel('Packet Reception Rate [%]')
ax.set_ylim([0, 120])
ax.set_yticks([0,20,40,60,80,100])
ax.set_xlim([-0.05,len(list(df.index.values)) - 0.95])
plt.title(title)
plt.savefig(if_phy + "_" + payload_size + "_" + offset + ".png")
plt.close()
else:
pass

0 comments on commit 2479524

Please sign in to comment.