本文整理汇总了Python中matplotlib.colors.LinearSegmentedColormap._lut[:-3,-1]方法的典型用法代码示例。如果您正苦于以下问题:Python LinearSegmentedColormap._lut[:-3,-1]方法的具体用法?Python LinearSegmentedColormap._lut[:-3,-1]怎么用?Python LinearSegmentedColormap._lut[:-3,-1]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.colors.LinearSegmentedColormap
的用法示例。
在下文中一共展示了LinearSegmentedColormap._lut[:-3,-1]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hist2d
# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import _lut[:-3,-1] [as 别名]
def hist2d(ax, x, y, sigs=[1], color="k", pcolor="grey", *args, **kwargs):
"""
Plot a 2-D histogram of samples.
"""
extent = kwargs.get("extent", None)
if extent is None:
extent = [[x.min(), x.max()], [y.min(), y.max()]]
bins = 45
linewidths = 0.8
# Instead of this, create a color map with the peak color.
if pcolor != "grey":
# print(pcolor)
r,g,b = pcolor
# print(r, g, b)
# Make our custom intensity scale
dict_cmap = {'red':[(0.0, r, r),
(1.0, 1.0, 1.0)],
'green': [(0.0, g, g),
(1.0, 1.0, 1.0)],
'blue': [(0.0, b, b),
(1.0, 1.0, 1.0)]}
cmap = LSC("new", dict_cmap)
else:
cmap = cm.get_cmap("gray")
cmap._init()
# The only thing he's changing here is the alpha interpolator, I think
# He's saying that we will have everything be black, and change alpha from 1 to 0.0
# cmap._lut[:-3, :-1] = 0.
cmap._lut[:-3, -1] = np.linspace(1, 0, cmap.N)
# N is the number of levels in the colormap
# Dunno what _lut is
# look up table
# Is he setting everything below some value to 0?
X = np.linspace(extent[0][0], extent[0][1], bins + 1)
# Y = np.linspace(extent[1][0], extent[1][1], bins + 1)
Y = np.logspace(np.log10(extent[1][0]), np.log10(extent[1][1]), bins + 1)
try:
H, X, Y = np.histogram2d(x.flatten(), y.flatten(), bins=(X, Y))
except ValueError:
raise ValueError("It looks like at least one of your sample columns "
"have no dynamic range. You could try using the "
"`extent` argument.")
# V = 1.0 - np.exp(-0.5 * np.array([1.0, 2.0, 3.0]) ** 2)
V = 1.0 - np.exp(-0.5 * np.array(sigs) ** 2)
#V = 1.0 - np.exp(-0.5 * np.arange(0.5, 2.1, 0.5) ** 2)
Hflat = H.flatten()
inds = np.argsort(Hflat)[::-1]
Hflat = Hflat[inds]
sm = np.cumsum(Hflat)
sm /= sm[-1]
for i, v0 in enumerate(V):
try:
V[i] = Hflat[sm <= v0][-1]
except:
V[i] = Hflat[0]
X1, Y1 = 0.5 * (X[1:] + X[:-1]), 0.5 * (Y[1:] + Y[:-1])
X, Y = X[:-1], Y[:-1]
# Plot the contours
ax.pcolor(X, Y, H.max() - H.T, cmap=cmap)
ax.contour(X1, Y1, H.T, V, colors=color, linewidths=linewidths)