Tim*_*imi 4 python matplotlib data-analysis python-3.x 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));
Run Code Online (Sandbox Code Playgroud)
我的困惑来自plt.cm.get_cmap('nipy_spectral',10)。有时会有plt.cm.get_cmap('RdYlBu')代替。
就是'RdYlBu','nipy_spectral'一个颜色的名称?还有其他名称可以代替吗?
是否有所有可用颜色的清单?
我已经阅读了该文档,但是它似乎无济于事,或者我听不懂。
的第一个参数plt.cm.get_cmap('nipy_spectral',10)是颜色图的名称。您可以通过获取所有可用颜色图的列表
import matplotlib.cm
print(matplotlib.cm.cmap_d.keys())
Run Code Online (Sandbox Code Playgroud)
或者您可以看一下颜色表参考。
从 matplotlib >= 1.5.0 开始,一种方法是调用更高级别的matplotlib.pyplot.colormaps()getter 函数,而不是直接访问较低级别的数据结构(例如,matplotlib.cm.cmap_d, matplotlib.cm.datad)。
调用matplotlib.pyplot.colormaps()的优点是隐式对所有返回的颜色图的名称进行排序(按字典顺序)。由于matplotlib.cm.cmap_d目前作为标准无序字典实现,因此打印或迭代其键,如ImportanceOfBeingErnest\'s 答案中所示中所示)阅读起来有点麻烦:例如,
# The pyplot.colormap() approach (works with matplotlib >= 1.5.0 ).\n>>> import matplotlib.pyplot as plt\n>>> print(plt.colormaps())\n[\'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\']\n\n# The direct matplotlib.cm approach (also works with matplotlib < 1.5.0)\n>>> import matplotlib.cm\n>>> print(matplotlib.cm.cmap_d.keys())\ndict_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\'])\nRun Code Online (Sandbox Code Playgroud)\n\n瞧\xc3\xa0!Sane API +人类可读性= 很好。
\n| 归档时间: |
|
| 查看次数: |
11180 次 |
| 最近记录: |