python颜色图量化(matplotlib) [英] python colormap quantisation (matplotlib)
本文介绍了python颜色图量化(matplotlib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Python中具有以下 colormap ,可将每个值映射到一种颜色.但我的问题是:如何量化在指定范围内获得相同颜色的值?例如:从0到10(绿色),从10到50(黄色),从50到55(红色),...
I have the following colormap in Python which maps each value to a color. But my question: How can I quantize the values for getting a same color for a specified range? For example: from 0 until 10 (Green) , from 10 until 50 (yellow), from 50 until 55 (red) , ...
import matplotlib as mpl
import matplotlib
from matplotlib import cm
.
.
.
norm = matplotlib.colors.Normalize(vmin = min,vmax = max, clip = True)
.
.
for i in range(numberMaterials):
step = (max-min)/numberMaterials
value = min + step*i
mat = bpy.data.materials.new("mat" +str(i))
color = cm.jet(norm(value),bytes=True)
推荐答案
您似乎在要求 BoundaryNorm
.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors
cmap = matplotlib.colors.ListedColormap(["limegreen", "gold", "crimson"])
norm = matplotlib.colors.BoundaryNorm([0,10,50,55], 3)
x = np.linspace(0,55)
fig, (ax, ax2) = plt.subplots(ncols=2)
sc = ax.scatter(x,x, c=x, cmap=cmap, norm=norm)
fig.colorbar(sc, ax=ax, spacing="uniform")
sc2 = ax2.scatter(x,x, c=x, cmap=cmap, norm=norm)
fig.colorbar(sc2, ax=ax2, spacing="proportional")
plt.show()
这篇关于python颜色图量化(matplotlib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文