Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python plt.cm.get\U cmap中可以使用哪些名称?_Python_Python 3.x_Matplotlib_Data Analysis_Matplotlib Basemap - Fatal编程技术网

Python plt.cm.get\U cmap中可以使用哪些名称?

Python plt.cm.get\U cmap中可以使用哪些名称?,python,python-3.x,matplotlib,data-analysis,matplotlib-basemap,Python,Python 3.x,Matplotlib,Data Analysis,Matplotlib Basemap,我有以下代码: plt.scatter(data_projected[:,0],data_projected[:,1],c=digits.target ,edgecolors='none',alpha=0.5,cmap=plt.cm.get_cmap('nipy_spectral',10)); 我的困惑来自于plt.cm.get\u cmap('nipy\u spectrum',10)。有时会出现plt.cm.get_cmap('RdYlBu') 'RdYlBu','n

我有以下代码:

plt.scatter(data_projected[:,0],data_projected[:,1],c=digits.target
        ,edgecolors='none',alpha=0.5,cmap=plt.cm.get_cmap('nipy_spectral',10));    
我的困惑来自于plt.cm.get\u cmap('nipy\u spectrum',10)。有时会出现plt.cm.get_cmap('RdYlBu')

'RdYlBu'
'nipy_spectrum'
是一种颜色的名称吗?还有其他名字可以用吗

是否有所有可用颜色的列表


我读过,但它似乎没有帮助,或者我不理解它。

plt.cm.get\u cmap('nipy\u spectrum',10)的第一个参数是彩色贴图的名称。您可以通过获取所有可用颜色贴图的列表

import matplotlib.cm
print(matplotlib.cm.cmap_d.keys())

或者您可以查看。

从matplotlib>=1.5.0开始,一种方法是调用而不是直接访问较低级别的数据结构(例如,
matplotlib.cm.cmap\u d
matplotlib.cm.datad

调用
matplotlib.pyplot.colormaps()
的优点是隐式排序所有返回的颜色映射的名称(按字典顺序)。由于
matplotlib.cm.cmap\u d
目前是作为标准无序字典实现的,因此打印或迭代其键会有点麻烦:例如

# The pyplot.colormap() approach (works with matplotlib >= 1.5.0 ).
>>> import matplotlib.pyplot as plt
>>> print(plt.colormaps())
['Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu', 'BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Greens', 'Greens_r', 'Greys', 'Greys_r', 'OrRd', 'OrRd_r', 'Oranges', 'Oranges_r', 'PRGn', 'PRGn_r', 'Paired', 'Paired_r', 'Pastel1', 'Pastel1_r', 'Pastel2', 'Pastel2_r', 'PiYG', 'PiYG_r', 'PuBu', 'PuBuGn', 'PuBuGn_r', 'PuBu_r', 'PuOr', 'PuOr_r', 'PuRd', 'PuRd_r', 'Purples', 'Purples_r', 'RdBu', 'RdBu_r', 'RdGy', 'RdGy_r', 'RdPu', 'RdPu_r', 'RdYlBu', 'RdYlBu_r', 'RdYlGn', 'RdYlGn_r', 'Reds', 'Reds_r', 'Set1', 'Set1_r', 'Set2', 'Set2_r', 'Set3', 'Set3_r', 'Spectral', 'Spectral_r', 'Wistia', 'Wistia_r', 'YlGn', 'YlGnBu', 'YlGnBu_r', 'YlGn_r', 'YlOrBr', 'YlOrBr_r', 'YlOrRd', 'YlOrRd_r', 'afmhot', 'afmhot_r', 'autumn', 'autumn_r', 'binary', 'binary_r', 'bone', 'bone_r', 'brg', 'brg_r', 'bwr', 'bwr_r', 'cividis', 'cividis_r', 'cool', 'cool_r', 'coolwarm', 'coolwarm_r', 'copper', 'copper_r', 'cubehelix', 'cubehelix_r', 'flag', 'flag_r', 'gist_earth', 'gist_earth_r', 'gist_gray', 'gist_gray_r', 'gist_heat', 'gist_heat_r', 'gist_ncar', 'gist_ncar_r', 'gist_rainbow', 'gist_rainbow_r', 'gist_stern', 'gist_stern_r', 'gist_yarg', 'gist_yarg_r', 'gnuplot', 'gnuplot2', 'gnuplot2_r', 'gnuplot_r', 'gray', 'gray_r', 'hot', 'hot_r', 'hsv', 'hsv_r', 'inferno', 'inferno_r', 'jet', 'jet_r', 'magma', 'magma_r', 'nipy_spectral', 'nipy_spectral_r', 'ocean', 'ocean_r', 'pink', 'pink_r', 'plasma', 'plasma_r', 'prism', 'prism_r', 'rainbow', 'rainbow_r', 'seismic', 'seismic_r', 'spring', 'spring_r', 'summer', 'summer_r', 'tab10', 'tab10_r', 'tab20', 'tab20_r', 'tab20b', 'tab20b_r', 'tab20c', 'tab20c_r', 'terrain', 'terrain_r', 'viridis', 'viridis_r', 'winter', 'winter_r']

# The direct matplotlib.cm approach (also works with matplotlib < 1.5.0)
>>> import matplotlib.cm
>>> print(matplotlib.cm.cmap_d.keys())
dict_keys(['Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Spectral', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv', 'jet', 'nipy_spectral', 'ocean', 'pink', 'prism', 'rainbow', 'seismic', 'spring', 'summer', 'terrain', 'winter', 'Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b', 'tab20c', 'Blues_r', 'BrBG_r', 'BuGn_r', 'BuPu_r', 'CMRmap_r', 'GnBu_r', 'Greens_r', 'Greys_r', 'OrRd_r', 'Oranges_r', 'PRGn_r', 'PiYG_r', 'PuBu_r', 'PuBuGn_r', 'PuOr_r', 'PuRd_r', 'Purples_r', 'RdBu_r', 'RdGy_r', 'RdPu_r', 'RdYlBu_r', 'RdYlGn_r', 'Reds_r', 'Spectral_r', 'Wistia_r', 'YlGn_r', 'YlGnBu_r', 'YlOrBr_r', 'YlOrRd_r', 'afmhot_r', 'autumn_r', 'binary_r', 'bone_r', 'brg_r', 'bwr_r', 'cool_r', 'coolwarm_r', 'copper_r', 'cubehelix_r', 'flag_r', 'gist_earth_r', 'gist_gray_r', 'gist_heat_r', 'gist_ncar_r', 'gist_rainbow_r', 'gist_stern_r', 'gist_yarg_r', 'gnuplot_r', 'gnuplot2_r', 'gray_r', 'hot_r', 'hsv_r', 'jet_r', 'nipy_spectral_r', 'ocean_r', 'pink_r', 'prism_r', 'rainbow_r', 'seismic_r', 'spring_r', 'summer_r', 'terrain_r', 'winter_r', 'Accent_r', 'Dark2_r', 'Paired_r', 'Pastel1_r', 'Pastel2_r', 'Set1_r', 'Set2_r', 'Set3_r', 'tab10_r', 'tab20_r', 'tab20b_r', 'tab20c_r', 'magma', 'magma_r', 'inferno', 'inferno_r', 'plasma', 'plasma_r', 'viridis', 'viridis_r', 'cividis', 'cividis_r'])
#pyplot.colormap()方法(适用于matplotlib>=1.5.0)。
>>>将matplotlib.pyplot作为plt导入
>>>打印(plt.colormaps())
['Accent'、'Accent_r'、'Blues'、'Blues_r'、'BrBG'、'BrBG_r'、'BuPu_r'、'CMRmap'、'CMRmap_r'、'Dark2_r'、'GnBu_r'、'Greens'、'Greens_r'、'Greys_r'、'OrRd'、'OrRd_r'、'OrRd_r'、'Order'、'Ordes'、'Ordes'、's、's、Ordes'、's、's、's、's、's、Orders、's、's、's、's、'Orders、's、's、's、's、's、's、'suBu、PuBuGn、PuBuGn、PuBu、PuBu、PuOr、PuOr、PuRd、PuRd、PuRd、紫色、紫色、RdBu、RdBu、RdBu、RdGy、RdGy、RdGy、RdGy、RdPu、RDPUU、RdYlBu、RdYlGn、RdYlGn、RdYlGn、RED、RED、RED、Set1、Set1、Set2、Set3、Set3、Set3、SETR、光谱、光谱、IA、Wistar、RdYlGn、YlGn、GNYL、GNGn_r、YlOrBr、YlOrBr、YlOrRd、YlOrRd、YlOrRd、afmhot、afmhot_r、秋天、秋天、二元、二元、骨头、骨头、骨头、骨头、brg、brg、brg_r、bwr、bwr、cividis、cividis_r、cool_r、coolwarm_r、copper、copper_r、cubehelix、cubehelix_r、flag、flag、flag_r、gist_earth r、gist_gray、Gis_圣格雷厄尔、吉斯特热、吉斯特热、吉斯特热、吉斯特热、吉斯特彩虹、吉斯特彩虹、吉斯特斯特恩、吉斯特斯特恩、吉斯特斯特恩、吉斯特亚格、吉斯特亚格、吉斯特亚格、吉斯特亚格、吉斯特亚格、格努洛特、格努洛特2、格努洛特2、格努洛特2、格努洛特、格瑞、格雷、格瑞、热、热、热、热、热、热、hsv、hsv、hsv、地狱、地狱、地狱、地狱、喷射光谱、岩浆、岩浆、喷射光谱、尼比铝、海洋、海洋、粉红、粉红、等离子、等离子、棱镜、棱镜、彩虹、彩虹、地震、地震、春天、春天、夏天、夏天、tab10、tab10、tab10、tab20、tab20b、tab20b、tab20c、tab20c、Tab20R、地形、绿色、绿色、冬季、冬季
#直接matplotlib.cm方法(也适用于matplotlib<1.5.0)
>>>导入matplotlib.cm
>>>打印(matplotlib.cm.cmap\u d.keys())
口述键(蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、橙、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝、蓝埃利克斯、旗帜、地球、灰色、热、ncar、彩虹、斯特恩、亚格、格努普洛特、格努普洛特、格努普洛特、格努普洛特、格努普洛特2、灰色、热、hsv、喷气式飞机、光谱、海洋、粉色、棱镜、彩虹、地震、春季、夏季、地形、冬季、口音、深色、成对的、贴片1、贴片2、贴片1、贴片2、贴片3、ta“B 10”、“20,”塔20,”20,”20,”20,”10,”20,”20,”20,”20,”20,”20,”10,”20,”20,”20,”20,”10,”10,”10,”10,”10,”10,”10,”10,”10,”10,”10,”10,”10,”10,”10,”10,”10,”20,”20,”20,”20,”20,”20,”10,”B,B,B,B,B,B,B,U,U,r,B,B,B,B,B,r,B,B,B,r,B,B,B,B,B,B,r,B,r,B,B,r,B,B,B,B,B,B,B,r,B,r,B,B,r,B,r,r,B,B,B,B,r,r,B,B,B,r,r,B,r,r,B,B,r,r,r,B,r,B,B,r,B,B,r,r,rd_r、afmhot_r、autumn_r、binary_r、bone_r、brg_r、bwr_r、cool_r、coolwarm_r、cubehelix r、flag_r、gist_earth_r、gist_gray_r、gist_heat_r、gist_ncar、gist_ncar、gist_stern_r、gist_yarg_r、Gnu_r、gnuplot_r、Gnup_r、gnuplot_2_r、gray_r、gray_r、hot___r、Hsu_、Hsu_r、Pi_、Pi_、Pir、Pi_、Pir_、Pir、Pirsm_r、彩虹_r、地震_r、春季_r、夏季_r、地形_r、冬季_r、重音_r、深色_r、成对_r、彩色_r、彩色_r、彩色_r、彩色_r、Set1_r、Set2_r、Set3_r、tab10_r、tab20_r、tab20b_r、tab20c_r、岩浆、岩浆、地狱、地狱、地狱、地狱、地狱、等离子、血浆、绿色、翡翠、绿色、Cividu r

瞧!Sane API+人类可读性=很好。

成功了!!!谢谢,我还得到了一些其他帮助。不幸的是,在matplotlib 3.3.1版中,我得到了
MatplotlibDeprecation警告:当我试图阅读时,全局彩色地图词典不再被视为公共API。
e> matplotlib.cm.cmap\u d
plt.cm.datad.keys()
生成所有颜色映射名称。请注意,
plt.colormaps()
仅返回排序后的
(matplotlib.cm.cmap\u d)不知道信息来自何处,但从我的理解<代码> CMAPGLD 不太可能在将来改变。此外,考虑到PyPrPad的使用通常是不需要的,而<>代码> MatPultLIb.cMc/Cd>到处都很容易被导入。