当前位置: 首页>>代码示例>>Python>>正文


Python LinearSegmentedColormap._init方法代码示例

本文整理汇总了Python中matplotlib.colors.LinearSegmentedColormap._init方法的典型用法代码示例。如果您正苦于以下问题:Python LinearSegmentedColormap._init方法的具体用法?Python LinearSegmentedColormap._init怎么用?Python LinearSegmentedColormap._init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.colors.LinearSegmentedColormap的用法示例。


在下文中一共展示了LinearSegmentedColormap._init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: hist2d

# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import _init [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)
开发者ID:Sandy4321,项目名称:ScottiePippen,代码行数:82,代码来源:full_HR.py


注:本文中的matplotlib.colors.LinearSegmentedColormap._init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。