Python Examples

The following are 1 code examples for showing how to use These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module , or try the search function .

Example 1
Project: pynoddy   Author: cgre-aachen   File:    License: GNU General Public License v2.0 4 votes vote down vote up
def build_edge_colormaps(self):
        Builds a colormap for each group of edges passed.
        The self.edge_colormap dict should have the following structure:
         { 'group_name' : {e1 : 'r', e2 : 0.4, e3: 0.2, cm=cm.Blues}, 'grp2' : 
         {e4 : 0.2, e5: 30, e6: 10, 'cm' : 'alpha', color' : 'r'}}
        import matplotlib.colors as cols
        if self.edge_colormap is None:
            self.edge_colormap = {}
        for group, edge_list in self.edges.iteritems():
            if not self.edge_colormap.has_key(group):
                self.edge_colormap[group] = {} #init group
            #get colormap
            c_map = self.edge_colormap[group].get('cm',cm.Blues)
            #calculate  value range
                minv = float(min ( [ v for v in self.edge_colormap[group].values()  if isinstance(v, numbers.Number)] ))
                maxv = float(max ( [ v for v in self.edge_colormap[group].values() if isinstance(v, numbers.Number)] ))
            except ValueError: #empty sequence
            for e in edge_list: #loop through edges in this group
                v = self.edge_colormap[group].get(e, 'b') #get color. default is blue.
                if isinstance(v, numbers.Number): #if value is a number (we need to use colour ramp)
                    if c_map == 'alpha': #map values to alpha
                        if not maxv == minv:
                            alpha = (v - minv) / (maxv - minv)
                            color = self.edge_colormap[group].get('color','b')
                            alpha = 0.6
                            color = self.edge_colormap[group].get('color','b')
                        rgb = cols.colorConverter.to_rgb(color)
                        self.edge_colormap[group][e] = rgb + (alpha,)
                    else: #use defined colormap
                        self.edge_colormap[group][e] = c_map( (v - minv) / (maxv - minv) )
                    #set default alpha to 0.6
                    rgb = cols.colorConverter.to_rgb(v)
                    self.edge_colormap[group][e] = rgb + (0.6,)