From 7eb34b5312974f601d1117eeaf6393b9648be31c Mon Sep 17 00:00:00 2001 From: Jonathan Herman Date: Fri, 12 Apr 2013 15:12:22 -0400 Subject: Improved error handling in parse_ and plot_exps.py. --- plot/style.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'plot/style.py') 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'])): class StyleMap(object): '''Maps configs (dicts) to specific line styles.''' - DEFAULT = Style('', '-', 'k') + DEFAULT = Style(marker='', line= '-', color='k') + ORDER = [ str, bool, float, int ] def __init__(self, col_list, col_values): '''Assign (some) columns in @col_list to fields in @Style to vary, and @@ -15,6 +16,17 @@ class StyleMap(object): self.value_map = {} self.field_map = {} + # Prioritize non-numbers + def type_priority(column): + value = col_values[column].pop() + col_values[column].add(value) + try: + t = float if float(value) % 1.0 else int + except: + t = bool if value in ['True','False'] else str + return StyleMap.ORDER.index(t) + col_list = sorted(col_list, key=type_priority) + # TODO: undo this, switch to popping mechanism for field, values in reversed([x for x in self.__get_all()._asdict().iteritems()]): if not col_list: @@ -31,9 +43,9 @@ class StyleMap(object): def __get_all(self): '''A Style holding all possible values for each property.''' - return Style(list('.,ov^<>1234sp*hH+xDd|_'), # markers - ['-', ':', '--'], # lines - list('bgrcmyk')) # colors + return Style(marker=list('.,ov^<>1234sp*hH+xDd|_'), + line=['-', ':', '--'], + color=list('bgrcmyk')) def get_style(self, kv): '''Translate column values to unique line style.''' -- cgit v1.2.2