cmap和颜色列表之间的区别(Difference between cmap and a list of colors)

系统教程 行业动态 更新时间:2024-06-14 16:57:40
cmap和颜色列表之间的区别(Difference between cmap and a list of colors)

色彩图( contour和许多其他绘图功能所需)和简单的颜色列表之间有什么区别? 如何将颜色列表(每种颜色应该代表相等大小的步骤)转换为颜色映射?

What's the difference between a colormap (as required by contour and many other plotting functions) and a simple list of colors? How do I convert a list of colors (where each color is supposed to be represent equal-sized step) into a colormap?

最满意答案

色彩图是一系列代表数量概念的颜色。 典型的色图(如喷射)为低值标记提供蓝色,为高值标记提供红色。 因此,您可以使用色彩图在图片中创建另一个维度。 对于matplotlib,如果你给出一种颜色,那么所有标记都会有这种颜色(所以它基本上是一种美学特征)。 如果给出色彩映射以及第三个变量,则该变量将被绘制为颜色而不是轴空间。

在轮廓的情况下,每种颜色可以表示更高或更低的高度(例如)。

您可以使用以下配方设置自己的离散色彩映射:

import matplotlib.pyplot as plt from matplotlib import colors import numpy as np def plot_matrix(rm, title='Robot World', cmap=plt.cm.Blues): plt.imshow(rm, interpolation='nearest', cmap=cmap) plt.title(title) plt.tight_layout() plt.show() cmap = colors.ListedColormap(['k','b','y','g','r']) bounds=[0,1,2,3,4] norm = colors.BoundaryNorm(bounds, cmap.N) rm = np.random.randint(0,4,(5,5)) plot_matrix(rm,cmap=cmap)

我从另一个问题中给出了一个类似的答案,你可以在这里看到。

A colormap is a series of colors that represent a notion of quantity. A typical colormap such as jet gives a blue color to low valued markers and red color for high valued markers. So you can use a colormap make another dimension into your picture. For matplotlib if you give a color all marker will have that color (so it's basically an aesthetic feature). If you give a colormap, together with a third variable, that variable will be plotted as color instead for axis space.

In the case of contour each color might represent a higher or lower altitude (for example).

You can set your own discrete colormap using the following recipe:

import matplotlib.pyplot as plt from matplotlib import colors import numpy as np def plot_matrix(rm, title='Robot World', cmap=plt.cm.Blues): plt.imshow(rm, interpolation='nearest', cmap=cmap) plt.title(title) plt.tight_layout() plt.show() cmap = colors.ListedColormap(['k','b','y','g','r']) bounds=[0,1,2,3,4] norm = colors.BoundaryNorm(bounds, cmap.N) rm = np.random.randint(0,4,(5,5)) plot_matrix(rm,cmap=cmap)

I brought this recipe from a similar answer I gave in another question you can see here.

更多推荐

本文发布于:2023-04-13 12:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/a21867d90f18bbcfc1fb289cca8c1bff.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   颜色   列表   cmap   list

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!