本文整理汇总了Python中matplotlib.cm.register_cmap函数的典型用法代码示例。如果您正苦于以下问题:Python register_cmap函数的具体用法?Python register_cmap怎么用?Python register_cmap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register_cmap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: make_my_cmaps
def make_my_cmaps():
# surface density color map
x = [-4.11 - sdoff, -3.11 - sdoff, -.931 - sdoff, .069 - sdoff]
# x[3] and x[0] are cdmax and cdmin below.
beginx = (x[1] - x[0]) / (x[3] - x[0])
begingray = 0.9
transitionx = (x[2] - x[0]) / (x[3] - x[0])
transitiongray = 0.35
finishr = 37 / 256
finishg = 49 / 256
finishb = 111 / 256
cdict = {'red': ((0.0, 1.0, 1.0),
(beginx, begingray, begingray),
(transitionx, transitiongray, transitiongray),
(1.0, finishr, finishr)),
'green': ((0.0, 1.0, 1.0),
(beginx, begingray, begingray),
(transitionx, transitiongray, transitiongray),
(1.0, finishg, finishg)),
'blue': ((0.0, 1.0, 1.0),
(beginx, begingray, begingray),
(transitionx, transitiongray, transitiongray),
(1.0, finishb, finishb))}
cmap1 = col.LinearSegmentedColormap('my_colormapSD', cdict, N=256, gamma=1.0)
cm.register_cmap(name='nickmapSD', cmap=cmap1)
开发者ID:nickolas1,项目名称:ramses_plot_scripts,代码行数:25,代码来源:make_plots_from_reduced_data.py
示例2: make_cmap
def make_cmap(colors, name="custom", position=None, bit=False):
"""
modified from http://schubert.atmos.colostate.edu/~cslocum/custom_cmap.html
make_cmap takes a list of tuples which contain RGB values. The RGB
values may either be in 8-bit [0 to 255] (in which bit must be set to
True when called) or arithmetic [0 to 1] (default). make_cmap returns
a cmap with equally spaced colors.
Arrange your tuples so that the first color is the lowest value for the
colorbar and the last is the highest.
position contains values from 0 to 1 to dictate the location of each color.
"""
import matplotlib as mpl
import matplotlib.cm as cm
import numpy as np
bit_rgb = np.linspace(0, 1, 256)
if position == None:
position = np.linspace(0, 1, len(colors))
else:
if len(position) != len(colors):
sys.exit("position length must be the same as colors")
elif position[0] != 0 or position[-1] != 1:
sys.exit("position must start with 0 and end with 1")
if bit:
for i in range(len(colors)):
colors[i] = (bit_rgb[colors[i][0]], bit_rgb[colors[i][1]], bit_rgb[colors[i][2]])
cdict = {"red": [], "green": [], "blue": []}
for pos, color in zip(position, colors):
cdict["red"].append((pos, color[0], color[0]))
cdict["green"].append((pos, color[1], color[1]))
cdict["blue"].append((pos, color[2], color[2]))
cmap = mpl.colors.LinearSegmentedColormap("custom", cdict, 256)
cm.register_cmap(name="custom", cmap=cmap)
return cmap
开发者ID:LucaRappez,项目名称:pySpatialMetabolomics,代码行数:35,代码来源:colourmaps.py
示例3: raw
def raw(self):
from matplotlib import colors, cm, pyplot as plt
import glob, os
# Get colormap from matplotlib or pycortex colormaps
## -- redundant code, here and in cortex/quicklflat.py -- ##
if isinstance(self.cmap, string_types):
if not self.cmap in cm.__dict__:
# unknown colormap, test whether it's in pycortex colormaps
cmapdir = options.config.get('webgl', 'colormaps')
colormaps = glob.glob(os.path.join(cmapdir, "*.png"))
colormaps = dict(((os.path.split(c)[1][:-4],c) for c in colormaps))
if not self.cmap in colormaps:
raise Exception('Unkown color map!')
I = plt.imread(colormaps[self.cmap])
cmap = colors.ListedColormap(np.squeeze(I))
# Register colormap while we're at it
cm.register_cmap(self.cmap,cmap)
else:
cmap = cm.get_cmap(self.cmap)
elif isinstance(self.cmap, colors.Colormap):
cmap = self.cmap
# Normalize colors according to vmin, vmax
norm = colors.Normalize(self.vmin, self.vmax)
cmapper = cm.ScalarMappable(norm=norm, cmap=cmap)
color_data = cmapper.to_rgba(self.data.flatten()).reshape(self.data.shape+(4,))
# rollaxis puts the last color dimension first, to allow output of separate channels: r,g,b,a = dataset.raw
return np.rollaxis(color_data, -1)
开发者ID:gallantlab,项目名称:pycortex,代码行数:27,代码来源:views.py
示例4: _has_cmap
def _has_cmap(dataview):
"""Checks whether a given dataview has colormap (cmap) information as an
instance or is an RGB volume and does not have a cmap.
Returns a dictionary with cmap information for non RGB volumes"""
from matplotlib import colors, cm, pyplot as plt
cmapdict = dict()
if not isinstance(dataview, (dataset.VolumeRGB, dataset.VertexRGB)):
# Get colormap from matplotlib or pycortex colormaps
## -- redundant code, here and in cortex/dataset/views.py -- ##
if isinstance(dataview.cmap,(str,unicode)):
if not dataview.cmap in cm.__dict__:
# unknown colormap, test whether it's in pycortex colormaps
cmapdir = config.get('webgl', 'colormaps')
colormaps = glob.glob(os.path.join(cmapdir, "*.png"))
colormaps = dict(((os.path.split(c)[1][:-4],c) for c in colormaps))
if not dataview.cmap in colormaps:
raise Exception('Unkown color map!')
I = plt.imread(colormaps[dataview.cmap])
cmap = colors.ListedColormap(np.squeeze(I))
# Register colormap while we're at it
cm.register_cmap(dataview.cmap,cmap)
else:
cmap = dataview.cmap
elif isinstance(dataview.cmap,colors.Colormap):
# Allow input of matplotlib colormap class
cmap = dataview.cmap
cmapdict.update(cmap=cmap,
vmin=dataview.vmin,
vmax=dataview.vmax)
return cmapdict
开发者ID:r-b-g-b,项目名称:pycortex,代码行数:34,代码来源:quickflat.py
示例5: register_lc_color_map
def register_lc_color_map():
lc_color_mappings = [
(0, dict(r=0, g=0, b=0)),
(10, dict(r=255, g=255, b=100)),
(11, dict(r=255, g=255, b=100)),
(12, dict(r=255, g=255, b=0)),
(20, dict(r=170, g=240, b=240)),
(30, dict(r=220, g=240, b=100)),
(40, dict(r=200, g=200, b=100)),
(50, dict(r=0, g=100, b=0)),
(60, dict(r=0, g=160, b=0)),
(61, dict(r=0, g=160, b=0)),
(62, dict(r=170, g=200, b=0)),
(70, dict(r=0, g=60, b=0)),
(71, dict(r=0, g=60, b=0)),
(72, dict(r=0, g=80, b=0)),
(80, dict(r=40, g=80, b=0)),
(81, dict(r=40, g=80, b=0)),
(82, dict(r=40, g=100, b=0)),
(90, dict(r=120, g=130, b=0)),
(100, dict(r=140, g=160, b=0)),
(110, dict(r=190, g=150, b=0)),
(120, dict(r=150, g=100, b=0)),
(121, dict(r=120, g=75, b=0)),
(122, dict(r=150, g=100, b=0)),
(130, dict(r=255, g=180, b=50)),
(140, dict(r=255, g=220, b=210)),
(150, dict(r=255, g=235, b=175)),
(151, dict(r=255, g=205, b=120)),
(152, dict(r=255, g=210, b=120)),
(153, dict(r=255, g=235, b=175)),
(160, dict(r=0, g=120, b=190)),
(170, dict(r=0, g=150, b=120)),
(180, dict(r=0, g=220, b=130)),
(190, dict(r=195, g=20, b=0)),
(200, dict(r=255, g=245, b=215)),
(201, dict(r=220, g=220, b=220)),
(202, dict(r=255, g=245, b=215)),
(210, dict(r=0, g=70, b=200)),
(220, dict(r=255, g=255, b=255)),
]
classes = {lc: color for lc, color in lc_color_mappings}
invalid_rgba = (0, 0, 0, 0.5)
class_0_rgba = (0, 0, 0, 0)
rgba_list = []
num_entries = 256
last_rgba = invalid_rgba
for i in range(num_entries):
color = classes.get(i)
if color:
last_rgba = (color['r'] / 255, color['g'] / 255, color['b'] / 255, 1.0)
rgba_list.append(last_rgba)
rgba_list[0] = class_0_rgba
cmap = matplotlib.colors.ListedColormap(rgba_list, name=LAND_COVER_CCI_CMAP, N=num_entries)
cm.register_cmap(cmap=cmap)
开发者ID:CCI-Tools,项目名称:ect-core,代码行数:59,代码来源:cmap_lc.py
示例6: register_cmap_safe
def register_cmap_safe(name, data):
"Register a colormap if not already registered."
try:
return cm.get_cmap(name)
except ValueError:
cmap = LinearSegmentedColormap.from_list(name, data)
cm.register_cmap(name, cmap)
return cmap
开发者ID:AbdealiJK,项目名称:scikit-image,代码行数:8,代码来源:colormap.py
示例7: discrete_cmap
def discrete_cmap(N=8):
"""create a colormap with N (N<15) discrete colors and register it"""
# define individual colors as hex values
cpool = [ '#bd2309', '#bbb12d', '#1480fa', '#14fa2f', '#000000',
'#faf214', '#2edfea', '#ea2ec4', '#ea2e40', '#cdcdcd',
'#577a4d', '#2e46c0', '#f59422', '#219774', '#8086d9' ]
cmap3 = col.ListedColormap(cpool[0:N], 'indexed')
cm.register_cmap(cmap=cmap3)
开发者ID:ameert,项目名称:astro_image_processing,代码行数:8,代码来源:register_cm.py
示例8: draw
def draw(map,svg=True,name='',hide=True,colorbar=False,notif=[]):
"""
Display the map as 2D array, with a specific color for each Cell nature and state
:param map: Map object which must be displayed
:param svg: boolean, determine if the image must be saved or not
:param name: string, add an additional name to 'imgXXX.png'
:param hide: boolean, toggle the display of the drawn image
:param colorbar: boolean, toggle the colorbar used at the right of the image
:param notif: string array, contains every notification which must be displayed
"""
map.calc_mat() #update the matrix
mx = int( np.amax(map.map) ) #max and min values of the matrix
mn = int( np.amin(map.map) ) #to determine the colormap used
simu_color = col.ListedColormap(cpool[(mn+1):(mx+2)], 'indexed')
cm.register_cmap(cmap=simu_color)
color = simu_color
if(hide): plt.ioff() #hide the poping windows of python
else: plt.ion()
if(colorbar): plt.colorbar() #show the colormap used to draw the matrix
#list of displayed fireman on the map, to draw bigger symbols when there is multiple firemen on same cell
frman_display = []
for frman in map.fireman_list:
new = True
for i in range(len(frman_display)):
if(frman.x == frman_display[i][0] and frman.y == frman_display[i][1]): #if there is already a fireman on this position
new = False
break
if(not new): frman_display[i][2] += 1 #size of the symbol whill be bigger
else: frman_display.append([frman.x,frman.y,0]) #new position to draw a symbol
plt.matshow(map.map,cmap=color) #display the map
for i in range(len(frman_display)): #display firemen with a red square
size = 3 + (frman_display[i][2])
plt.plot(frman_display[i][0],frman_display[i][1],'rs',markersize=size)
for i in range(len(notif)): #display the notifications
plt.text(0,i*2, notif[i], color='w')
wind_dir = ['N','NE','E','SE','S','SW','W','NW']
if(map.wind_active): plt.text(0,map.size,'wind: '+ wind_dir[map.wind], color='b') #display wind notification
plt.text(map.size/2, map.size, str(len(map.fireman_list)) + ' firemen alive', color='r') #display number of firemen
plt.axis([-0.5,map.size-0.5,-0.5,map.size-0.5]) #resize the image
plt.axis('off') #hide the axis
if(svg):
txt = "images/img" + str(map.count+100) + name + ".png" #image's name, +100 for index problems (conversion)
plt.savefig(txt,dpi=200,bbox_inches='tight',pad_inches=0)
开发者ID:hdebray,项目名称:S.I.E.R.R.A.,代码行数:58,代码来源:display.py
示例9: discrete_cmap
def discrete_cmap(N=7):
# define individual colors as hex values
cpool = [ '#FF6E30', '#D05A27', '#AA4920', '#883A19', '#662C13',
'#311509', '#000000']
# TODO: build cpool as a sequence of colors of variying value (from 0 to 255) in hsv color space, then convert to hex
discrete_cmap = col.ListedColormap(cpool[0:N], 'discrete_copper')
cm.register_cmap(cmap=discrete_cmap)
开发者ID:Yukee,项目名称:python-plot,代码行数:9,代码来源:discrete_colormap.py
示例10: calculate_em
def calculate_em(self, wlen='171', dz=100, model=False):
"""
Calculate an approximation of the coronal EmissionMeasure using a given
TemperatureMap object and a particular AIA channel.
Parameters
----------
tmap : CoronaTemps.temperature.TemperatureMap
A TemperatureMap instance containing coronal temperature data
wlen : {'94' | '131' | '171' | '193' | '211' | '335'}
AIA wavelength used to approximate the emission measure. '171', '193'
and '211' are most likely to provide reliable results. Use of other
channels is not recommended.
"""
# Load the appropriate temperature response function
tresp = read('/imaps/holly/home/ajl7/CoronaTemps/aia_tresp')
resp = tresp['resp{}'.format(wlen)]
# Get some information from the TemperatureMap and set up filenames, etc
tempdata = self.data.copy()
tempdata[np.isnan(tempdata)] = 0.0
date = sunpy.time.parse_time(self.date)
if not model:
data_dir = self.data_dir
fits_dir = path.join(data_dir, '{:%Y/%m/%d}/{}'.format(date, wlen))
filename = path.join(fits_dir,
'*{0:%Y?%m?%d}?{0:%H?%M}*fits'.format(date))
if wlen == '94': filename = filename.replace('94', '094')
# Load and appropriately process AIA data
filelist = glob.glob(filename)
if filelist == []:
print 'AIA data not found :('
return
aiamap = Map(filename)
aiamap.data /= aiamap.exposure_time
aiamap = aiaprep(aiamap)
aiamap = aiamap.submap(self.xrange, self.yrange)
else:
fname = '/imaps/holly/home/ajl7/CoronaTemps/data/synthetic/{}/model.fits'.format(wlen)
if wlen == '94': fname = fname.replace('94', '094')
aiamap = Map(fname)
# Create new Map and put EM values in it
emmap = Map(self.data.copy(), self.meta.copy())
indices = np.round((tempdata - 4.0) / 0.05).astype(int)
indices[indices < 0] = 0
indices[indices > 100] = 100
#print emmap.shape, indices.shape, tempdata.shape, aiamap.shape, resp.shape
emmap.data = np.log10(aiamap.data / resp[indices])
#emmap.data = aiamap.data / resp[indices]
emmapcubehelix = _cm.cubehelix(s=2.8, r=-0.7, h=1.4, gamma=1.0)
cm.register_cmap(name='emhelix', data=emmapcubehelix)
emmap.cmap = cm.get_cmap('emhelix')
return emmap
开发者ID:Cadair,项目名称:CoronaTemps,代码行数:57,代码来源:temperature.py
示例11: register_idl_colormaps
def register_idl_colormaps():
from matplotlib.cm import register_cmap
names = []
for x in range(40):
cmap = loadct(x)
name = 'idl'+str(x)
register_cmap(name = name, cmap = cmap)
names.append(name)
return names
开发者ID:piScope,项目名称:piScope,代码行数:9,代码来源:cbook.py
示例12: james
def james():
"""David James suggested color ramp Yellow to Blue """
cpool = ['#FFFF80', '#CDFA64', '#98F046', '#61E827', '#3BD923', '#3FC453',
'#37AD7A', '#26989E', '#217AA3', '#215394', '#1B3187', '#0C1078']
cmap3 = mpcolors.ListedColormap(cpool, 'james')
cmap3.set_over("#000000")
cmap3.set_under("#FFFFFF")
cmap3.set_bad("#FFFFFF")
cm.register_cmap(cmap=cmap3)
return cmap3
开发者ID:akrherz,项目名称:pyIEM,代码行数:10,代码来源:colormaps.py
示例13: james2
def james2():
"""David James suggested color ramp Yellow to Brown"""
cpool = ['#FFFF80', '#FFEE70', '#FCDD60', '#FACD52', '#F7BE43', '#F5AF36',
'#E69729', '#CC781F', '#B35915', '#9C400E', '#822507', '#6B0000']
cmap3 = mpcolors.ListedColormap(cpool, 'james2')
cmap3.set_over("#000000")
cmap3.set_under("#FFFFFF")
cmap3.set_bad("#FFFFFF")
cm.register_cmap(cmap=cmap3)
return cmap3
开发者ID:akrherz,项目名称:pyIEM,代码行数:10,代码来源:colormaps.py
示例14: discrete_cmap
def discrete_cmap(N=14):
# define individual colors as hex values
cpool = [ '#FFC57E', '#FFB573', '#FEA167', '#EE9760', '#D88758', '#BF794D', '#A66943', '#8F5A39', '#76492E', '#5F3C26', '#492D1D', '#2F1D13',
'#1A0F0A', '#000000']
cpool = cpool[::-1]
# TODO: build cpool as a sequence of colors of variying value (from 0 to 255) in hsv color space, then convert to hex
discrete_cmap = col.ListedColormap(cpool[0:N], 'discrete_copper')
cm.register_cmap(cmap=discrete_cmap)
开发者ID:Yukee,项目名称:python-plot,代码行数:10,代码来源:imshowContour.py
示例15: newgray
def newgray():
""" Modified version of Oranges."""
oranges = cm.get_cmap("gray", 100)
array = oranges(np.arange(100))
array = array[40:]
cmap = LinearSegmentedColormap.from_list("newgray", array)
cm.register_cmap(name='newgray', cmap=cmap)
array = array[::-1]
cmap = LinearSegmentedColormap.from_list("newgray_r", array)
cm.register_cmap(name='newgray_r', cmap=cmap)
return
开发者ID:kadubarbosa,项目名称:hydrakin,代码行数:11,代码来源:newcolorbars.py
示例16: discrete_cmap
def discrete_cmap(N=8):
"""create a colormap with N (N<15) discrete colors and register it"""
# define individual colors as hex values
# #9E0142
cpool = ['#D085A4', '#D53E4F', '#F46D43', '#FDAE61', '#FEE08B',
'#E6F598', '#ABDDA4', '#66C2A5', '#3288BD', '#5E4FA2']
if N == 5:
cmap3 = col.ListedColormap(cpool[::2], 'nice_spectral')
else:
cmap3 = col.ListedColormap(cpool[0:N], 'nice_spectral')
cm.register_cmap(cmap=cmap3)
开发者ID:adrn,项目名称:streams,代码行数:11,代码来源:core.py
示例17: plotUsage
def plotUsage(data, name='File Usage' ,outname = 'filestuff', limits = None, points=None, subtitle = None):
'''plot the file layout data given a a list of MB transformed by the method
in this file'''
plt.figure()
newData = []
row = 0
for i in data:
if row % 2 == 0:
newData.append(i)
row = row + 1
data = numpy.array(newData)
# define the colormap
clrMap = plt.cm.jet
# extract all colors from the .jet map
cmaplist = [clrMap(i) for i in xrange(clrMap.N)]
# force the first color entry to be grey
cmaplist[0] = (1.0,1.0,1.0,1.0)
# create the new map
clrMap = clrMap.from_list('custommap', cmaplist, clrMap.N)
cm.register_cmap(name='custommap', cmap=clrMap)
#get axis
maxy = len(data)
maxx = pow(1,20)
plt.pcolormesh(data,vmin = 1, cmap='custommap')#, cmap = mcolor.colormap('gist_ncar'))
plt.xlabel('Offset within Mb (kb)')
plt.ylabel('Mb Offset in File')
if len(name) > 100:
plt.title(name, fontsize=8)
else:
plt.title(name, fontsize=10)
plt.colorbar()
if points != None:
px = [i[0] for i in points]
py = [i[1]/2 for i in points]
plt.scatter(px,py, marker=(5,1), c='goldenrod')
#fix the y labels
spacing = int(maxy/10)
locs = [y for y in xrange(0, maxy,spacing)]
labs = [str(y) for y in locs]
plt.yticks(locs,labs)
plt.xlim(0,maxx)
plt.ylim(0,maxy)
locs = [256, 512, 789, 1024]
labs = [str(x) for x in locs]
plt.xticks(locs,labs)
plt.savefig(outname+ '.png')
开发者ID:akoerner,项目名称:HCC-Swanson,代码行数:53,代码来源:HCCPlot.py
示例18: add_cmap
def add_cmap(name, cdict):
"""
Adds a colormap to the colormaps available in yt for this session
"""
yt_colormaps[name] = \
cc.LinearSegmentedColormap(name,cdict,256)
mcm.datad[name] = cdict
mcm.__dict__[name] = cdict
try: # API compatibility
mcm.register_cmap(name, yt_colormaps[name])
except AttributeError:
pass
开发者ID:danielgrassinger,项目名称:yt_new_frontend,代码行数:12,代码来源:color_maps.py
示例19: dep_erosion
def dep_erosion():
"""DEP Erosion ramp yelllow to brown (jump at 5T) `cool`"""
cpool = [
'#FFFF80', '#FCDD60', '#F7BE43', '#E69729', '#B35915', '#822507',
'#00ffff', '#2ad5ff', '#55aaff', '#807fff', '#aa55ff', '#d52aff',
]
cmap = mpcolors.ListedColormap(cpool, 'dep_erosion')
cmap.set_over("#000000")
cmap.set_under("#FFFFFF")
cmap.set_bad("#FFFFFF")
cm.register_cmap(cmap=cmap)
return cmap
开发者ID:akrherz,项目名称:pyIEM,代码行数:12,代码来源:colormaps.py
示例20: getColorMap
def getColorMap():
"""
This function returns the standard University of Tuebingen Colormap.
"""
midBlue = np.array([165, 30, 55])/255
lightBlue = np.array([210, 150, 0])/255
steps = 200
MAP = mcolors.LinearSegmentedColormap.from_list('Tuebingen', \
[midBlue, lightBlue, [1,1,1]],N = steps, gamma = 1.0)
cm.register_cmap(name = 'Tuebingen', cmap = MAP)
return MAP
开发者ID:Visdoom,项目名称:psignifit-4.0,代码行数:12,代码来源:psigniplot.py
注:本文中的matplotlib.cm.register_cmap函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论