Index: plots/plot_csv_files.py |
diff --git a/plots/plot_csv_files.py b/plots/plot_csv_files.py |
index ab4172297d70e3a2207a9f9499995d0e560ff5a6..a8f58505eb949e0e4fd4e50703c50cfbc7833dea 100755 |
--- a/plots/plot_csv_files.py |
+++ b/plots/plot_csv_files.py |
@@ -28,30 +28,32 @@ def prase_src_file_args(f): |
x_cols = [] |
y_cols = [] |
- for i in range(1, len(tokens), 2): |
- x_cols.append(int(tokens[i])) |
- y_cols.append(int(tokens[i+1])) |
+ plot_labels = [] |
+ for i in range(1, len(tokens), 3): |
+ plot_labels.append(tokens[i]) |
+ x_cols.append(int(tokens[i+1])) |
+ y_cols.append(int(tokens[i+2])) |
- return ifname, x_cols, y_cols |
+ return ifname, plot_labels, x_cols, y_cols |
def plot_csv(f): |
- ifname, x_cols, y_cols = prase_src_file_args(f) |
+ ifname, plot_labels, x_cols, y_cols = prase_src_file_args(f) |
df = pd.read_csv(ifname, sep=get_separator()) |
- # df.names = |
- # print x_cols, y_cols |
- |
- for xcol, ycol in zip(x_cols, y_cols): |
+ y_vals_list = [] |
+ for label, xcol, ycol in zip(plot_labels, x_cols, y_cols): |
x = list(df[df.columns[xcol]]) |
y = list(df[df.columns[ycol]]) |
- plt.plot(x, y) |
+ plt.plot(x, y, label=label) |
+ |
+ y_vals_list.append(y) |
- # print df |
+ return y_vals_list |
if __name__ == '__main__': |
@@ -63,7 +65,6 @@ if __name__ == '__main__': |
parser.add_argument("--out_file", default="out_csv.png", type=str, |
help="The name of the output file") |
- |
parser.add_argument("--xlabel", default="Time", type=str, |
help="Label on the X axis") |
@@ -73,8 +74,15 @@ if __name__ == '__main__': |
parser.add_argument("--title", default="Title", type=str, |
help="Title of the plot") |
+ parser.add_argument("--legend_position", default=2, type=int, |
+ help="Integer number defining position of the legend, see matplotlib docs") |
+ |
+ parser.add_argument("--ylim_percentiles", nargs='*', default=[0,100], type=str, |
+ help="""Min and max percentile among all input files to limit the plot. For visibility""") |
+ |
parser.add_argument("--src_files", nargs='*', default=[], type=str, |
- help="""List of strings of the format <file_name>,<x1_col>,<y1_col>,<x2_col>,<y2_col>""") |
+ help="""List of strings of the format <file_name>,<label_1>,<x1_col>,<y1_col>,<label_2>,<x2_col>,<y2_col> |
+ For example: i1_rate.nslrack3.1.log.csv,1,2 i1_rate.nslrack6.1.log.csv,1,2 i1_rate.nslrack7.1.log.csv,1,2""") |
parser.add_argument("--delimeter", default="comma", type=str, choices=["comma", "space"], |
help="""Type of the delimeters allowed""") |
@@ -82,8 +90,7 @@ if __name__ == '__main__': |
FLAGS = parser.parse_args() |
- plt.figure(dpi=1000, figsize=(10,6)) |
- |
+ plt.figure(dpi=1000, figsize=(20,12)) |
plt.ylabel(FLAGS.ylabel) |
@@ -91,9 +98,15 @@ if __name__ == '__main__': |
plt.title(FLAGS.title) |
+ y_val_list = [] |
for f in FLAGS.src_files: |
- plot_csv(f) |
+ y_val_list += plot_csv(f) |
+ |
+ y_min, y_max = suggest_plots_lims( |
+ y_val_list, FLAGS.ylim_percentiles[0], FLAGS.ylim_percentiles[1]) |
+ plt.ylim(y_min, y_max) |
plt.grid() |
- log.info("Output file: {}".format(FLAGS.out_file)) |
- plt.savefig(FLAGS.out_file, bbox_inches='tight') |
+ plt.legend(loc=FLAGS.legend_position) |
+ log.info("Output file: %s", format(FLAGS.out_file)) |
+ plt.savefig(FLAGS.out_file, bbox_inches='tight') |