matplotlib 中的 colors 和 cmaps

懵懂的女人 提交于 2019-12-14 19:45:34

matplotlib 中的 148 种颜色

matplotlib 中的 160 种颜色映射

 

1、matplotlib中的 148 种颜色

import matplotlib as plm
import matplotlib.pyplot as plt

colors = plm.colors.cnames.keys()

fig = plt.figure('百里希文', facecolor='lightyellow', edgecolor='k')
axes = fig.subplots(len(colors)//4, 4)

for c, ax in zip(colors, axes.ravel()):
    ax.hist(1, 3, color=c)
    ax.text(1.2, 0.1, c)
    ax.set_axis_off()
fig.subplots_adjust(left=0, bottom=0, right=0.9,
                    top=1, hspace=0.1, wspace=0.1)  
fig.show()

 

2 matplotlib 中的 160 种颜色映射

import numpy as npimport matplotlib as plm
import matplotlib.pyplot as plt

cmaps = plm.cm.cmap_d.keys()
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))  

fig = plt.figure('百里希文', facecolor='lightyellow', edgecolor='k')
axes = fig.subplots(len(cmaps)//5, 5)

for cmap, ax in zip(cmaps, axes.ravel()):
    ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(cmap))
    ax.text(100, 1, cmap, fontsize=14)
    ax.set_axis_off()
    
fig.subplots_adjust(left=0.1, bottom=0, right=0.9,
                    top=1, hspace=0.1, wspace=0.1)    
fig.show()

 

按语:

推荐几篇文章

https://cloud.tencent.com/developer/ask/136207/answer/241390

https://blog.csdn.net/Mr_Cat123/article/details/78638491

https://www.cnblogs.com/charliedaifu/p/9957822.html

https://blog.csdn.net/zhaogeng111/article/details/78419015

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!