本文整理匯總了Python中matplotlib.cm.cmap_d方法的典型用法代碼示例。如果您正苦於以下問題:Python cm.cmap_d方法的具體用法?Python cm.cmap_d怎麽用?Python cm.cmap_d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.cm
的用法示例。
在下文中一共展示了cm.cmap_d方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_cmap
# 需要導入模塊: from matplotlib import cm [as 別名]
# 或者: from matplotlib.cm import cmap_d [as 別名]
def get_cmap( cmap, name=None, n=256 ):
""" in: a name "Blues" "BuGn_r" ... of a builtin cmap (case-sensitive)
or a filename, np.loadtxt() n x 3 or 4 ints 0..255 or floats 0..1
or a cmap already
or a numpy array.
See http://wiki.scipy.org/Cookbook/Matplotlib/Show_colormaps
or in IPython, pl.cm.<tab>
"""
if isinstance( cmap, colors.Colormap ):
return cmap
if isinstance( cmap, str ):
if cmap in cm.cmap_d:
return pl.get_cmap( cmap ) # "Blues" ...
A = np.loadtxt( cmap, delimiter=None ) # None: white space
name = name or cmap.split("/")[-1] .split(".")[0] # .../xx.csv -> xx
else:
A = cmap # numpy array or array-like
return array_cmap( A, name, n=n )
示例2: _list_cmaps
# 需要導入模塊: from matplotlib import cm [as 別名]
# 或者: from matplotlib.cm import cmap_d [as 別名]
def _list_cmaps(provider=None, records=False):
"""
List available colormaps by combining matplotlib, bokeh, and
colorcet colormaps or palettes if available. May also be
narrowed down to a particular provider or list of providers.
"""
if provider is None:
provider = providers
elif isinstance(provider, basestring):
if provider not in providers:
raise ValueError('Colormap provider %r not recognized, must '
'be one of %r' % (provider, providers))
provider = [provider]
cmaps = []
def info(provider,names):
return [CMapInfo(name=n,provider=provider,category=None,source=None,bg=None) for n in names] \
if records else list(names)
if 'matplotlib' in provider:
try:
import matplotlib.cm as cm
cmaps += info('matplotlib',
[cmap for cmap in cm.cmap_d if not
(cmap.startswith('cet_') or # duplicates list below
cmap.startswith('Vega') or # deprecated in matplotlib=2.1
cmap.startswith('spectral') )]) # deprecated in matplotlib=2.1
except:
pass
if 'bokeh' in provider:
try:
from bokeh import palettes
cmaps += info('bokeh', palettes.all_palettes)
cmaps += info('bokeh', [p+'_r' for p in palettes.all_palettes])
except:
pass
if 'colorcet' in provider:
try:
from colorcet import palette_n, glasbey_hv
cet_maps = palette_n.copy()
cet_maps['glasbey_hv'] = glasbey_hv # Add special hv-specific map
cmaps += info('colorcet', cet_maps)
cmaps += info('colorcet', [p+'_r' for p in cet_maps])
except:
pass
return sorted(unique_iterator(cmaps))