aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plot/style.py2
-rwxr-xr-xplot_exps.py35
2 files changed, 20 insertions, 17 deletions
diff --git a/plot/style.py b/plot/style.py
index 7e964b0..ca7a112 100644
--- a/plot/style.py
+++ b/plot/style.py
@@ -7,7 +7,7 @@ class Style(namedtuple('SS', ['marker', 'line', 'color'])):
7 7
8class StyleMap(object): 8class StyleMap(object):
9 '''Maps configs (dicts) to specific line styles.''' 9 '''Maps configs (dicts) to specific line styles.'''
10 DEFAULT = Style('.', '-', 'k') 10 DEFAULT = Style('', '', 'k')
11 11
12 def __init__(self, col_list, col_values): 12 def __init__(self, col_list, col_values):
13 '''Assign (some) columns in @col_list to fields in @Style to vary, and 13 '''Assign (some) columns in @col_list to fields in @Style to vary, and
diff --git a/plot_exps.py b/plot_exps.py
index bb6a707..b17cd36 100755
--- a/plot_exps.py
+++ b/plot_exps.py
@@ -7,9 +7,8 @@ import shutil as sh
7import sys 7import sys
8from collections import namedtuple 8from collections import namedtuple
9from optparse import OptionParser 9from optparse import OptionParser
10from parse.col_map import ColMap 10from parse.col_map import ColMap,ColMapBuilder
11from parse.dir_map import DirMap 11from parse.dir_map import DirMap
12from parse.tuple_table import ReducedTupleTable
13from plot.style import StyleMap 12from plot.style import StyleMap
14 13
15def parse_args(): 14def parse_args():
@@ -39,26 +38,32 @@ def get_details(path, out_dir):
39 38
40 return ExpDetails(variable, value, title, out) 39 return ExpDetails(variable, value, title, out)
41 40
42def plot_by_variable(plot_node, col_map, details): 41def plot_by_variable(plot_node, details):
43 '''Plot each .csv files under @plot_node as a line on a shared plot.''' 42 '''Plot each .csv files under @plot_node as a line on a shared plot.'''
44 43
44 builder = ColMapBuilder()
45 config_nodes = []
46
45 # Generate mapping of (column)=>(line property to vary) for consistently 47 # Generate mapping of (column)=>(line property to vary) for consistently
46 # formatted plots 48 # formatted plots
47 columns = list(col_map.columns()) 49 for line_path, line_node in plot_node.children.iteritems():
48 if details.variable and details.variable in columns: 50 encoded = line_path[:line_path.index(".csv")]
49 columns.remove(details.variable) 51 line_config = ColMap.decode(encoded)
50 style_map = StyleMap(columns, col_map.get_values()) 52
53 for k, v in line_config.iteritems():
54 builder.try_add(k, v)
55 config_nodes += [(line_config, line_node)]
56
57 col_map = builder.build()
58 style_map = StyleMap(col_map.columns(), col_map.get_values())
51 59
52 figure = plot.figure() 60 figure = plot.figure()
53 axes = figure.add_subplot(111) 61 axes = figure.add_subplot(111)
54 62
55 # Create a line for each file node 63 # Create a line for each file node and its configuration
56 for line_path, line_node in plot_node.children.iteritems(): 64 for line_config, line_node in config_nodes:
57 # Create line style to match this configuration 65 # Create line style to match this configuration
58 encoded = line_path[:line_path.index(".csv")] 66 style = style_map.get_style(line_config)
59 config = ColMap.decode(encoded)
60 style = style_map.get_style(config)
61
62 values = sorted(line_node.values, key=lambda tup: tup[0]) 67 values = sorted(line_node.values, key=lambda tup: tup[0])
63 xvalues, yvalues = zip(*values) 68 xvalues, yvalues = zip(*values)
64 69
@@ -81,8 +86,6 @@ def plot_dir(data_dir, out_dir, force):
81 dir_map = DirMap.read(data_dir) 86 dir_map = DirMap.read(data_dir)
82 87
83 sys.stderr.write("Creating column map...\n") 88 sys.stderr.write("Creating column map...\n")
84 tuple_table = ReducedTupleTable.from_dir_map(dir_map)
85 col_map = tuple_table.get_col_map()
86 89
87 if not os.path.exists(out_dir): 90 if not os.path.exists(out_dir):
88 os.mkdir(out_dir) 91 os.mkdir(out_dir)
@@ -97,7 +100,7 @@ def plot_dir(data_dir, out_dir, force):
97 details = get_details(plot_path, out_dir) 100 details = get_details(plot_path, out_dir)
98 101
99 if force or not os.path.exists(details.out): 102 if force or not os.path.exists(details.out):
100 plot_by_variable(plot_node, col_map, details) 103 plot_by_variable(plot_node, details)
101 104
102 plot_num += 1 105 plot_num += 1
103 106