本文整理汇总了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,)