码迷,mamicode.com
首页 > 其他好文 > 详细

colormap中的内嵌彩色模块和调用方式

时间:2019-02-18 19:01:32      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:ext   ane   enter   代码   ace   tle   form   实例   lan   

内嵌彩色模块代码:

import numpy as np
import matplotlib.pyplot as plt

# Have colormaps separated into categories:
# http://matplotlib.org/examples/color/colormaps_reference.html

cmaps = [(‘Perceptually Uniform Sequential‘,
[‘viridis‘, ‘inferno‘, ‘plasma‘, ‘magma‘]),
(‘Sequential‘, [‘Blues‘, ‘BuGn‘, ‘BuPu‘,
‘GnBu‘, ‘Greens‘, ‘Greys‘, ‘Oranges‘, ‘OrRd‘,
‘PuBu‘, ‘PuBuGn‘, ‘PuRd‘, ‘Purples‘, ‘RdPu‘,
‘Reds‘, ‘YlGn‘, ‘YlGnBu‘, ‘YlOrBr‘, ‘YlOrRd‘]),
(‘Sequential (2)‘, [‘afmhot‘, ‘autumn‘, ‘bone‘, ‘cool‘,
‘copper‘, ‘gist_heat‘, ‘gray‘, ‘hot‘,
‘pink‘, ‘spring‘, ‘summer‘, ‘winter‘]),
(‘Diverging‘, [‘BrBG‘, ‘bwr‘, ‘coolwarm‘, ‘PiYG‘, ‘PRGn‘, ‘PuOr‘,
‘RdBu‘, ‘RdGy‘, ‘RdYlBu‘, ‘RdYlGn‘, ‘Spectral‘,
‘seismic‘]),
(‘Qualitative‘, [‘Accent‘, ‘Dark2‘, ‘Paired‘, ‘Pastel1‘,
‘Pastel2‘, ‘Set1‘, ‘Set2‘, ‘Set3‘]),
(‘Miscellaneous‘, [‘gist_earth‘, ‘terrain‘, ‘ocean‘, ‘gist_stern‘,
‘brg‘, ‘CMRmap‘, ‘cubehelix‘,
‘gnuplot‘, ‘gnuplot2‘, ‘gist_ncar‘,
‘nipy_spectral‘, ‘jet‘, ‘rainbow‘,
‘gist_rainbow‘, ‘hsv‘, ‘flag‘, ‘prism‘])]

nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))


def plot_color_gradients(cmap_category, cmap_list):
fig, axes = plt.subplots(nrows=nrows)
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
axes[0].set_title(cmap_category + ‘ colormaps‘, fontsize=14)

for ax, name in zip(axes, cmap_list):
ax.imshow(gradient, aspect=‘auto‘, cmap=plt.get_cmap(name))
pos = list(ax.get_position().bounds)
x_text = pos[0] - 0.01
y_text = pos[1] + pos[3] / 2.
fig.text(x_text, y_text, name, va=‘center‘, ha=‘right‘, fontsize=10)

# Turn off *all* ticks & spines, not just the ones with colormaps.
for ax in axes:
ax.set_axis_off()


for cmap_category, cmap_list in cmaps:
plot_color_gradients(cmap_category, cmap_list)

plt.show()

生成的彩色图像:
常用的:

技术图片

技术图片

技术图片


实例代码:
import matplotlib.pyplot as plt
x= list(range(0,1000,2))
y= list(range(1,501))
plt.scatter(x,y,c=x,cmap= plt.cm.flag,alpha=0.5,s=20)
plt.show()
图像:
技术图片

 



注释:c=“” 让图像中的颜色随着某个数值变化
cmap=plt.cm.rainbow 彩色映射的图例,rainbow 处写colormap图像中前面的代码即可出现相应的映射。

colormap中的内嵌彩色模块和调用方式

标签:ext   ane   enter   代码   ace   tle   form   实例   lan   

原文地址:https://www.cnblogs.com/daimatuo/p/10397085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!