當前位置: 首頁>>代碼示例>>Python>>正文


Python cm.Blues方法代碼示例

本文整理匯總了Python中matplotlib.cm.Blues方法的典型用法代碼示例。如果您正苦於以下問題:Python cm.Blues方法的具體用法?Python cm.Blues怎麽用?Python cm.Blues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在matplotlib.cm的用法示例。


在下文中一共展示了cm.Blues方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: build_edge_colormaps

# 需要導入模塊: from matplotlib import cm [as 別名]
# 或者: from matplotlib.cm import Blues [as 別名]
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
            try:
                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
                minv=0
                maxv=0
            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')
                        else:
                            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) )
                else:
                    #set default alpha to 0.6
                    rgb = cols.colorConverter.to_rgb(v)
                    self.edge_colormap[group][e] = rgb + (0.6,) 
開發者ID:cgre-aachen,項目名稱:pynoddy,代碼行數:49,代碼來源:hive_plot.py


注:本文中的matplotlib.cm.Blues方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。