diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-12 15:12:22 -0400 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-12 15:12:22 -0400 |
| commit | 7eb34b5312974f601d1117eeaf6393b9648be31c (patch) | |
| tree | 838df63d06886bd3bbec560add8a1ac4ef4dd069 /plot | |
| parent | 09bc409657606a37346d82ab1e4c44a165bd3541 (diff) | |
Improved error handling in parse_ and plot_exps.py.
Diffstat (limited to 'plot')
| -rw-r--r-- | plot/style.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/plot/style.py b/plot/style.py index 21c4e7e..4e2057f 100644 --- a/plot/style.py +++ b/plot/style.py | |||
| @@ -7,7 +7,8 @@ class Style(namedtuple('SS', ['marker', 'line', 'color'])): | |||
| 7 | 7 | ||
| 8 | class StyleMap(object): | 8 | class 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(marker='', line= '-', color='k') |
| 11 | ORDER = [ str, bool, float, int ] | ||
| 11 | 12 | ||
| 12 | def __init__(self, col_list, col_values): | 13 | def __init__(self, col_list, col_values): |
| 13 | '''Assign (some) columns in @col_list to fields in @Style to vary, and | 14 | '''Assign (some) columns in @col_list to fields in @Style to vary, and |
| @@ -15,6 +16,17 @@ class StyleMap(object): | |||
| 15 | self.value_map = {} | 16 | self.value_map = {} |
| 16 | self.field_map = {} | 17 | self.field_map = {} |
| 17 | 18 | ||
| 19 | # Prioritize non-numbers | ||
| 20 | def type_priority(column): | ||
| 21 | value = col_values[column].pop() | ||
| 22 | col_values[column].add(value) | ||
| 23 | try: | ||
| 24 | t = float if float(value) % 1.0 else int | ||
| 25 | except: | ||
| 26 | t = bool if value in ['True','False'] else str | ||
| 27 | return StyleMap.ORDER.index(t) | ||
| 28 | col_list = sorted(col_list, key=type_priority) | ||
| 29 | |||
| 18 | # TODO: undo this, switch to popping mechanism | 30 | # TODO: undo this, switch to popping mechanism |
| 19 | for field, values in reversed([x for x in self.__get_all()._asdict().iteritems()]): | 31 | for field, values in reversed([x for x in self.__get_all()._asdict().iteritems()]): |
| 20 | if not col_list: | 32 | if not col_list: |
| @@ -31,9 +43,9 @@ class StyleMap(object): | |||
| 31 | 43 | ||
| 32 | def __get_all(self): | 44 | def __get_all(self): |
| 33 | '''A Style holding all possible values for each property.''' | 45 | '''A Style holding all possible values for each property.''' |
| 34 | return Style(list('.,ov^<>1234sp*hH+xDd|_'), # markers | 46 | return Style(marker=list('.,ov^<>1234sp*hH+xDd|_'), |
| 35 | ['-', ':', '--'], # lines | 47 | line=['-', ':', '--'], |
| 36 | list('bgrcmyk')) # colors | 48 | color=list('bgrcmyk')) |
| 37 | 49 | ||
| 38 | def get_style(self, kv): | 50 | def get_style(self, kv): |
| 39 | '''Translate column values to unique line style.''' | 51 | '''Translate column values to unique line style.''' |
