matplotlib 可视化 —— cmap(colormap)
程序员文章站
2022-03-27 08:54:41
...
<a href=“http://matplotlib.org/examples/color/colormaps_reference.html”, target="_blank">color example code: colormaps_reference.py — Matplotlib 2.0.0 documentation
由其文档可知,在 colormap 类别上,有如下分类:
- perceptual uniform sequential colormaps:感知均匀的序列化 colormap
- sequential colormaps:序列化(连续化)色图 colormap;
- gray:0-255 级灰度,0:黑色,1:白色,黑底白字;
- gray_r:翻转 gray 的显示,如果 gray 将图像显示为黑底白字,gray_r 会将其显示为白底黑字;
- binary
- diverging colormaps:两端发散的色图 colormaps;
- seismic
- qualitative colormaps:量化(离散化)色图;
- miscellaneous colormaps:其他色图;
- rainbow
1. matplotlib
-
设置 cmap 的几种方式:
plt.imshow(image, cmap=plt.get_cmap('gray_r'))plt.imshow(image, cmap='gray_r')plt.imshow(image, cmap=plt.cm.binary)
- 1
- 2
- 3
2. ListedColormap
class ListedColormap(Colormap): """Colormap object generated from a list of colors. ... """
- 1
- 2
- 3
- 4
from matplotlib.colors import ListedColormapcolors = ('lightgreen', 'cyan', 'gray', 'r', 'b')cmp = ListedColormap(colors[:np.unique(y_train)])
- 1
- 2
- 3
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow
推荐阅读