简体   繁体   English

Matplotlib 颜色图映射与稳定值

[英]Matplotlib colormap mapping with stable value

thanks for help.感谢帮助。

Here is the question:这是问题:

I have some values of earthquake Intensity(1, 2, 3, 4, 5, 5.5, 6, 6.5, 7 total 9 levels), And I also have 9 colors for colormap.我有一些地震强度值(1、2、3、4、5、5.5、6、6.5、7 共 9 个级别),我还有 9 个 colors 用于颜色图。

    color_map = [
        '#f3f3f3',
        '#1aff1a',
        '#ffff00',
        '#ff8900',
        '#ff5500',
        '#b64100',
        '#993300',
        '#aa3c00',
        '#800080'
]
cm = matplotlib.colors.ListedColormap(color_map)

draw_area.plot("Intensity", ax=axes, cmap=cm, legend=True) #it suppose to be mapped by "Intensity" values

and two cases happened并且发生了两个案例

Situation1: If I got many "different" values of "Intensity" such as 1,2,3,4,5,6,6.5,7 than my map came out with many colors like this.情况1:如果我得到许多“强度”的“不同”值,例如 1、2、3、4、5、6、6.5、7,那么我的 map 会出现许多这样的 colors。 情况1

Situation2: If I got many "Same" values of "Intensity" such as 4,4,4,4,4 or 5,5,5,5,5 than my map will not map the colormap, it came out with same color.(all areas mapped by the first color #f3f3f3)情况2:如果我得到许多“强度”的“相同”值,例如 4,4,4,4,4 或 5,5,5,5,5 比我的 map 不会 map 颜色图,它出来的颜色相同.(由第一种颜色映射的所有区域#f3f3f3) 情况2

I want to map the color "one value to one color", how to solve this?(if i got 2,2,2,2, these areas suppose to be mapped by #1aff1a)我想要 map 颜色“一个值到一个颜色”,如何解决这个问题?(如果我得到 2、2、2、2,这些区域假设由 #1aff1a 映射)

Thanks for help!感谢帮助!

I have found the method to this situation, I need to use absolute value to map the colors.我已经找到了解决这种情况的方法,我需要使用绝对值来map colors。

So I fix the code, and it works!所以我修复了代码,它可以工作!

here is the code:这是代码:

cmap, norm = matplotlib.colors.from_levels_and_colors(cLevel, color_map, extend="max")

Using from_levels_and_colors to get absolute mapping.使用 from_levels_and_colors 获取绝对映射。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM