Пример #1
0
 def __init__(self, bs={}, order=['hatch', 'facecolor',
                                  'edgecolor', 'linestyle'],
              sticks={}):
     #validity check
     for key in bs.keys():
         if key not in BarStyles.STYLE_KEYS:
             raise KeyError('Invalid key for line style: %s' %key)
     for key in order:
         if key not in BarStyles.STYLE_KEYS:
             raise KeyError('Invalid key for line style: %s' %key)
     for key in sticks:
         if key not in BarStyles.STYLE_KEYS:
             raise KeyError('Invalid key for line style: %s' %key)
     #assign default styles
     self.bs = bs
     if not self.bs.has_key('edgecolor') or self.bs['edgecolor'] is None:
         self.bs['edgecolor'] = COLORS
     if not self.bs.has_key('facecolor') or self.bs['facecolor'] is None:
         self.bs['facecolor'] = COLORS
     if not self.bs.has_key('hatch') or self.bs['hatch'] is None:
         self.bs['hatch'] = HATCHES
     if not self.bs.has_key('linestyle') or self.bs['linestyle'] is None:
         self.bs['linestyle'] = LINE_STYLES
     #assign other attributes
     self.order = order
     #stick
     self.sticks = sticks
     #iterator
     self.it = MultiListIterator(bs, order, sticks=sticks)
Пример #2
0
 def __init__(self, ls={}, order=['marker', 'color', 'conn'], sticks={}):
     #validity check
     for key in ls.keys():
         if key not in LineStyles.STYLE_KEYS:
             raise KeyError('Invalid key for line style: %s' %key)
     for key in order:
         if key not in LineStyles.STYLE_KEYS:
             raise KeyError('Invalid key for line style: %s' %key)
     for key in sticks:
         if key not in LineStyles.STYLE_KEYS:
             raise KeyError('Invalid key for line style: %s' %key)
     #assign default styles
     self.ls = ls
     if not self.ls.has_key('marker') or self.ls['marker'] is None:
         self.ls['marker'] = LINE_MARKERS.keys()
     if not self.ls.has_key('conn') or self.ls['conn'] is None:
         self.ls['conn'] = LINE_STYLES.keys()
     if not self.ls.has_key('color') or self.ls['color'] is None:
         self.ls['color'] = LINE_COLORS
     #assign other attributes
     self.order = order
     #stick
     self.sticks = sticks
     #iterator
     self.it = MultiListIterator(ls, order, sticks=sticks)
Пример #3
0
class BarStyles(object):
    """
    A collection of bar styles to iterate through.

    Style key:
        edgecolor, facecolor, hatch, linestyle

    Constructor options:
        bs      --  a dictionary of bar styles
        order   --  the order of change when iterates
        stick   --  stick two styles together.
    """
    STYLE_KEYS = ['edgecolor', 'facecolor', 'hatch', 'linestyle']
    def __init__(self, bs={}, order=['hatch', 'facecolor',
                                     'edgecolor', 'linestyle'],
                 sticks={}):
        #validity check
        for key in bs.keys():
            if key not in BarStyles.STYLE_KEYS:
                raise KeyError('Invalid key for line style: %s' %key)
        for key in order:
            if key not in BarStyles.STYLE_KEYS:
                raise KeyError('Invalid key for line style: %s' %key)
        for key in sticks:
            if key not in BarStyles.STYLE_KEYS:
                raise KeyError('Invalid key for line style: %s' %key)
        #assign default styles
        self.bs = bs
        if not self.bs.has_key('edgecolor') or self.bs['edgecolor'] is None:
            self.bs['edgecolor'] = COLORS
        if not self.bs.has_key('facecolor') or self.bs['facecolor'] is None:
            self.bs['facecolor'] = COLORS
        if not self.bs.has_key('hatch') or self.bs['hatch'] is None:
            self.bs['hatch'] = HATCHES
        if not self.bs.has_key('linestyle') or self.bs['linestyle'] is None:
            self.bs['linestyle'] = LINE_STYLES
        #assign other attributes
        self.order = order
        #stick
        self.sticks = sticks
        #iterator
        self.it = MultiListIterator(bs, order, sticks=sticks)

    def next(self):
        vals = self.it.next()
        if vals is None:
            self.it.reset()
            vals = self.it.next()
        curr = BarStyle()
        order_idx = 0
        val_idx = 0
        while True:
            if val_idx == len(vals):
                break
            val = vals[val_idx]
            orderkey = self.order[order_idx]
            setattr(curr, orderkey, val)
            val_idx += 1
            order_idx += 1
            if self.sticks.has_key(orderkey):
                for key in self.sticks[orderkey]:
                    val = vals[val_idx]
                    setattr(curr, key, val)
                    val_idx += 1
        return curr
Пример #4
0
class LineStyles(object):
    """
    A collection of line styles to iterate through.

    Style key:
        marker, color, conn

    Constructor options:
        ls      --  a dictionary of line styles
        order   --  the order of change when iterates
        stick   --  stick two styles together.
    """
    STYLE_KEYS = ['marker', 'color', 'conn']
    def __init__(self, ls={}, order=['marker', 'color', 'conn'], sticks={}):
        #validity check
        for key in ls.keys():
            if key not in LineStyles.STYLE_KEYS:
                raise KeyError('Invalid key for line style: %s' %key)
        for key in order:
            if key not in LineStyles.STYLE_KEYS:
                raise KeyError('Invalid key for line style: %s' %key)
        for key in sticks:
            if key not in LineStyles.STYLE_KEYS:
                raise KeyError('Invalid key for line style: %s' %key)
        #assign default styles
        self.ls = ls
        if not self.ls.has_key('marker') or self.ls['marker'] is None:
            self.ls['marker'] = LINE_MARKERS.keys()
        if not self.ls.has_key('conn') or self.ls['conn'] is None:
            self.ls['conn'] = LINE_STYLES.keys()
        if not self.ls.has_key('color') or self.ls['color'] is None:
            self.ls['color'] = LINE_COLORS
        #assign other attributes
        self.order = order
        #stick
        self.sticks = sticks
        #iterator
        self.it = MultiListIterator(ls, order, sticks=sticks)

    def next(self):
        vals = self.it.next()
        if vals is None:
            self.it.reset()
            vals = self.it.next()
        curr = LineStyle()
        order_idx = 0
        val_idx = 0
        while True:
            if val_idx == len(vals):
                break
            val = vals[val_idx]
            orderkey = self.order[order_idx]
            setattr(curr, orderkey, val)
            val_idx += 1
            order_idx += 1
            if self.sticks.has_key(orderkey):
                for key in self.sticks[orderkey]:
                    val = vals[val_idx]
                    setattr(curr, key, val)
                    val_idx += 1
        return curr