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


Python ColorConverter.to_rgba_array方法代码示例

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


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

示例1: plotBoundary

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba_array [as 别名]
def plotBoundary(dataset='iris', split=0.7, doboost=False, boostiter=5, covdiag=True, filename='', exportImg=False):
    X, y, pcadim = fetchDataset(dataset)
    xTr, yTr, xTe, yTe, trIdx, teIdx = trteSplitEven(X, y, split)
    pca = decomposition.PCA(n_components=2)
    pca.fit(xTr)
    xTr = pca.transform(xTr)
    xTe = pca.transform(xTe)

    pX = np.vstack((xTr, xTe))
    py = np.hstack((yTr, yTe))

    if doboost:
        ## Boosting
        # Compute params
        priors, mus, sigmas, alphas = trainBoost(xTr, yTr, T=boostiter, covdiag=covdiag)
    else:
        ## Simple
        # Compute params
        prior = computePrior(yTr)
        mu, sigma = mlParams(xTr, yTr)

    xRange = np.arange(np.min(pX[:, 0]), np.max(pX[:, 0]), np.abs(np.max(pX[:, 0]) - np.min(pX[:, 0])) / 100.0)
    yRange = np.arange(np.min(pX[:, 1]), np.max(pX[:, 1]), np.abs(np.max(pX[:, 1]) - np.min(pX[:, 1])) / 100.0)

    grid = np.zeros((yRange.size, xRange.size))

    for (xi, xx) in enumerate(xRange):
        for (yi, yy) in enumerate(yRange):
            if doboost:
                ## Boosting
                grid[yi, xi] = classifyBoost(np.matrix([[xx, yy]]), priors, mus, sigmas, alphas, covdiag=covdiag)
            else:
                ## Simple
                grid[yi, xi] = classify(np.matrix([[xx, yy]]), prior, mu, sigma, covdiag=covdiag)

    classes = range(np.min(y), np.max(y) + 1)
    ys = [i + xx + (i * xx) ** 2 for i in range(len(classes))]
    colormap = cm.rainbow(np.linspace(0, 1, len(ys)))

    plt.hold(True)
    conv = ColorConverter()
    for (color, c) in zip(colormap, classes):
        try:
            CS = plt.contour(xRange, yRange, (grid == c).astype(float), 15, linewidths=0.25,
                             colors=conv.to_rgba_array(color))
        except ValueError:
            pass
        xc = pX[py == c, :]
        plt.scatter(xc[:, 0], xc[:, 1], marker='o', c=color, s=40, alpha=0.5)

    plt.xlim(np.min(pX[:, 0]), np.max(pX[:, 0]))
    plt.ylim(np.min(pX[:, 1]), np.max(pX[:, 1]))
    if exportImg:
        plt.savefig(filename + '.png', dpi=400)
        plt.clf()
    else:
        plt.show()
开发者ID:haidelber,项目名称:machinelearning15kth,代码行数:59,代码来源:lab3.py

示例2: export_to_agr

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba_array [as 别名]
def export_to_agr(figure, filename, **kwargs):
    """
    Export a matplotlib figure to xmgrace format.
    """
    cc = ColorConverter()
    agr = AgrFile()
    # agr_attr_lists['color'] = ['white', 'black']
    # agr_colors =
    papersize = figure.get_size_inches()*120
    agr.writeline('page size {}, {}'.format(*papersize))
    for i, axis in enumerate(figure.axes):

        agr_axis = 'g{}'.format(i)
        agr.indent = 0
        agr.writeline('{axis} on', axis=agr_axis)
        agr.writeline('{axis} hidden false')
        agr.writeline('{axis} type XY')
        agr.writeline('{axis} stacked false')
        agr.writeline('with {axis}')
        agr.indent = 4

        process_attributes(agr_axis_attrs, axis, agr, **kwargs)

        for j, line in enumerate(axis.lines):
            agr.kwargs['line'] = 's{}'.format(j)
            process_attributes(agr_line_attrs, line, agr, '{line} ', **kwargs)
            agr.writedata(line.get_xydata())

        for text in axis.texts:
            agr.indent = 0
            agr.writeline('with string')
            agr.indent = 4
            process_attributes(agr_text_attrs, text, agr, 'string ', **kwargs)

            # this is a text of an arrow-annotation
            if hasattr(text, 'arrow_patch'):
                agr.indent = 0
                agr.writeline('with line')
                agr.indent = 4
                agr.writeline(f'line {agr_axis}')
                process_attributes(agr_arrow_attrs, text, agr, 'line ', **kwargs)
                agr.indent = 0
                agr.writeline('line def')


    agr.indent = 0
    tudcol_rev = {}
    for name, color in tudcolors.items():
        if isinstance(color, str):
            rgba, = cc.to_rgba_array(color)
            tudcol_rev[tuple(rgba)] = name           

    for i, color in enumerate(ValueAttribute.attr_lists['color']):
        # print(i, color)
        if color is not 'none':
            rgba, = cc.to_rgba_array(color)
            rgb_tuple = tuple(int(255 * c) for c in rgba[:3])
            color_name = tudcol_rev.get(tuple(rgba), color)
            agr.writeline('map color {index} to {rgb}, "{color}"',
                          part='head', index=i, rgb=rgb_tuple, color=color_name)

    agr.save(filename)
开发者ID:nielsmde,项目名称:tudplot,代码行数:64,代码来源:xmgrace.py

示例3: plotBoundary

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba_array [as 别名]
def plotBoundary(dataset='iris',split=0.7,doboost=False,boostiter=5,covdiag=True):
    
    X,y,pcadim = fetchDataset(dataset)
    xTr,yTr,xTe,yTe,trIdx,teIdx = trteSplitEven(X,y,split)
    pca = decomposition.PCA(n_components=2)
    pca.fit(xTr)
    xTr = pca.transform(xTr)
    xTe = pca.transform(xTe)
    
    pX = np.vstack((xTr, xTe))
    py = np.hstack((yTr, yTe))
    #print "Steg 1  #####################\n"
    if doboost:
        ## Boosting
        # Compute params
        priors,mus,sigmas,alphas = trainBoost(xTr,yTr,T=boostiter)  
        
    else:
        ## Simple
        # Compute params
        prior = computePrior(yTr)
        mu, sigma = mlParams(xTr,yTr)
    #print "Slut Steg 1 ##########################\n"
    xRange = np.arange(np.min(pX[:,0]),np.max(pX[:,0]),0.1)
    yRange = np.arange(np.min(pX[:,1]),np.max(pX[:,1]),0.1)

    grid = np.zeros((yRange.size, xRange.size))
    for (xi, xx) in enumerate(xRange):
        #print xx
        #print xi
        for (yi, yy) in enumerate(yRange):
            if doboost:
                ## Boosting 
                X = np.matrix([[xx,yy]])
                grid_point = classifyBoost(X,priors,mus,sigmas,alphas, covdiag=covdiag)
                #print grid_point
                #xx = int(xx)
                #yy = int (yy)
                grid[yi,xi]=grid_point       
            else:
                ## Simple
                #print "fore grid ###############\n"
                #print classify(np.matrix([[xx, yy]]),prior,mu,sigma,covdiag=covdiag)
                #grid[yi,xi] = classify(np.matrix([[xx, yy]]),prior,mu,sigma,covdiag=covdiag)
                grid[yi,xi] = classify(list([[xx, yy]]),prior,mu,sigma,covdiag=covdiag)
                #print "efter grid ##############\n"
    classes = range(np.min(y), np.max(y)+1)
    ys = [i+xx+(i*xx)**2 for i in range(len(classes))]
    colormap = cm.rainbow(np.linspace(0, 1, len(ys)))

    plt.hold(True)
    conv = ColorConverter()
    for (color, c) in zip(colormap, classes):

        CS = plt.contour(xRange,yRange,(grid==c).astype(float),15,linewidths=0.25,colors=conv.to_rgba_array(color))
        xc = pX[py == c, :]
        plt.scatter(xc[:,0],xc[:,1],marker='o',c=color,s=40,alpha=0.5)
        
    plt.xlim(np.min(pX[:,0]),np.max(pX[:,0]))
    plt.ylim(np.min(pX[:,1]),np.max(pX[:,1]))
    plt.show()
开发者ID:AndFroSwe,项目名称:ML_Lab3,代码行数:63,代码来源:main.py


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