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


Python colors.cnames方法代码示例

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


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

示例1: _to_hex

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def _to_hex(c):
    """Convert arbitray color specification to hex string."""
    ctype = type(c)

    # Convert rgb to hex.
    if ctype is tuple or ctype is np.ndarray or ctype is list:
        return colors.rgb2hex(c)

    if ctype is str:
        # If color is already hex, simply return it.
        regex = re.compile('^#[A-Fa-f0-9]{6}$')
        if regex.match(c):
            return c

        # Convert named color to hex.
        return colors.cnames[c]

    raise Exception("Can't handle color of type: {}".format(ctype)) 
开发者ID:atmtools,项目名称:typhon,代码行数:20,代码来源:common.py

示例2: lighten_color

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def lighten_color(color, amount=0.5):
    """
    Lightens the given color by multiplying (1-luminosity) by the given amount.
    Input can be matplotlib color string, hex string, or RGB tuple.

    Examples:
    >> lighten_color('g', 0.3)
    >> lighten_color('#F034A3', 0.6)
    >> lighten_color((.3,.55,.1), 0.5)
    """
    import matplotlib.colors as mc
    import colorsys
    try:
        c = mc.cnames[color]
    except:
        c = color
    c = colorsys.rgb_to_hls(*mc.to_rgb(c))
    return colorsys.hls_to_rgb(c[0], 1 - amount * (1 - c[1]), c[2]) 
开发者ID:flav-io,项目名称:flavio,代码行数:20,代码来源:colors.py

示例3: darken_color

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def darken_color(color, amount=0.5):
    """
    Darkens the given color by multiplying luminosity by the given amount.
    Input can be matplotlib color string, hex string, or RGB tuple.

    Examples:
    >> lighten_color('g', 0.3)
    >> lighten_color('#F034A3', 0.6)
    >> lighten_color((.3,.55,.1), 0.5)
    """
    import matplotlib.colors as mc
    import colorsys
    try:
        c = mc.cnames[color]
    except:
        c = color
    c = colorsys.rgb_to_hls(*mc.to_rgb(c))
    return colorsys.hls_to_rgb(c[0], amount * c[1], c[2]) 
开发者ID:flav-io,项目名称:flavio,代码行数:20,代码来源:colors.py

示例4: gen_colors

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def gen_colors():
	colors = ['#263133',
			  '#FE5016',
	          '#0073E7',
	          '#19A26B',
	          '#FCDB1F',
	          '#000000',
	          '#2A6A74',
	          '#861889',
	          '#00B4E0',
	          '#90EE90',
	          '#FF7F50',
	          '#B03A89']
	all_colors = [item for item in plt_colors.cnames]
	shuffle(all_colors)
	for c in all_colors:
		if c not in colors:
			colors += [c]
	return colors
#---# 
开发者ID:vertica,项目名称:VerticaPy,代码行数:22,代码来源:plot.py

示例5: test_standard_colors_all

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def test_standard_colors_all(self):
        import matplotlib.colors as colors
        from pandas.plotting._style import _get_standard_colors

        # multiple colors like mediumaquamarine
        for c in colors.cnames:
            result = _get_standard_colors(num_colors=1, color=c)
            assert result == [c]

            result = _get_standard_colors(num_colors=1, color=[c])
            assert result == [c]

            result = _get_standard_colors(num_colors=3, color=c)
            assert result == [c] * 3

            result = _get_standard_colors(num_colors=3, color=[c])
            assert result == [c] * 3

        # single letter colors like k
        for c in colors.ColorConverter.colors:
            result = _get_standard_colors(num_colors=1, color=c)
            assert result == [c]

            result = _get_standard_colors(num_colors=1, color=[c])
            assert result == [c]

            result = _get_standard_colors(num_colors=3, color=c)
            assert result == [c] * 3

            result = _get_standard_colors(num_colors=3, color=[c])
            assert result == [c] * 3 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:test_series.py

示例6: plot_objectivefunctiontraces

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def plot_objectivefunctiontraces(results,evaluation,algorithms,fig_name='Like_trace.png'):
    import matplotlib.pyplot as plt
    from matplotlib import colors
    cnames=list(colors.cnames)
    font = {'family' : 'calibri',
        'weight' : 'normal',
        'size'   : 20}
    plt.rc('font', **font)
    fig=plt.figure(figsize=(16,3))
    xticks=[5000,15000]

    for i in range(len(results)):
        ax  = plt.subplot(1,len(results),i+1)
        likes=calc_like(results[i],evaluation,spotpy.objectivefunctions.rmse)
        ax.plot(likes,'b-')
        ax.set_ylim(0,25)
        ax.set_xlim(0,len(results[0]))
        ax.set_xlabel(algorithms[i])
        ax.xaxis.set_ticks(xticks)
        if i==0:
            ax.set_ylabel('RMSE')
            ax.yaxis.set_ticks([0,10,20])
        else:
            ax.yaxis.set_ticks([])

    plt.tight_layout()
    fig.savefig(fig_name) 
开发者ID:thouska,项目名称:spotpy,代码行数:29,代码来源:analyser.py

示例7: rgb_custom_colormap

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def rgb_custom_colormap(colors=None, alpha=None, N=256):
    """Creates a custom colormap. Colors can be given as names or rgb values.

    Arguments
    ---------
    colors: : `list` or `array` (default `['royalblue', 'white', 'forestgreen']`)
        List of colors, either as names or rgb values.
    alpha: `list`, `np.ndarray` or `None` (default: `None`)
        Alpha of the colors. Must be same length as colors.
    N: `int` (default: `256`)
        y coordinate

    Returns
    -------
        A ListedColormap
    """
    if colors is None:
        colors = ["royalblue", "white", "forestgreen"]
    c = []
    if "transparent" in colors:
        if alpha is None:
            alpha = [1 if i != "transparent" else 0 for i in colors]
        colors = [i if i != "transparent" else "white" for i in colors]

    for color in colors:
        if isinstance(color, str):
            color = to_rgb(color if color.startswith("#") else cnames[color])
            c.append(color)
    if alpha is None:
        alpha = np.ones(len(c))

    vals = np.ones((N, 4))
    ints = len(c) - 1
    n = int(N / ints)

    for j in range(ints):
        for i in range(3):
            vals[n * j : n * (j + 1), i] = np.linspace(c[j][i], c[j + 1][i], n)
        vals[n * j : n * (j + 1), -1] = np.linspace(alpha[j], alpha[j + 1], n)
    return ListedColormap(vals) 
开发者ID:theislab,项目名称:scvelo,代码行数:42,代码来源:utils.py

示例8: getColorNames

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def getColorNames():
    
    colorNames = []
    for color in colors.cnames:    
        colorNames.append(color)
    
    return colorNames 
开发者ID:md-k-sarker,项目名称:Predicting-Health-Insurance-Cost,代码行数:9,代码来源:DataAnalysis.py

示例9: assign_color

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def assign_color(self, n):
        '''
        assigns a color
        if n <= len(base_colors) assigns the base color whose index is n - 1
        else generates a random color
        '''
        color = None
        if n <= len(self.base_colors):
            color = ref_colors.cnames[self.base_colors[n - 1]] # get hex representation
        else:
            color = self.__generate_random_color()

        self.used_colors.append(color)
    
        return color 
开发者ID:cstoeckert,项目名称:iterativeWGCNA,代码行数:17,代码来源:colors.py

示例10: is_color

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def is_color(color):
    """
    Checks if supplied object is a valid color spec.
    """
    if not isinstance(color, basestring):
        return False
    elif RGB_HEX_REGEX.match(color):
        return True
    elif color in COLOR_ALIASES:
        return True
    elif color in cnames:
        return True
    return False 
开发者ID:holoviz,项目名称:holoviews,代码行数:15,代码来源:util.py

示例11: adjust_lightness

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def adjust_lightness(color, amount=0.7):
    """Lightens the given color by multiplying (1-luminosity) by the given amount.

    Input can be matplotlib color string, hex string, or RGB tuple.
    Output will be an RGB string."""
    import matplotlib.colors as mc
    import colorsys
    try:
        c = mc.cnames[color]
    except:
        c = color
    c = colorsys.rgb_to_hls(*mc.to_rgb(c))
    rgb = colorsys.hls_to_rgb(c[0], max(0, min(1, amount * c[1])), c[2])
    return 'rgb(%d,%d,%d)' % (int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255)) 
开发者ID:polakowo,项目名称:vectorbt,代码行数:16,代码来源:colors.py

示例12: plot

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def plot(func, xpoints, color_name, xlabel, ylabel, theme, gui, line_style, file_path, discrete=False):

    # Show plot summary
    print('***** Plot Summary *****')
    print("Funtion: {}".format(func))

    if discrete:

        print("Plotting funcion for points: {}".format(', '.join(map(str, xpoints))))
    else:
        print("Starting abcissa: {}".format(xpoints[0]))
        print("Ending abcissa: {}".format(xpoints[-1]))
        if (len(xpoints) > 1):
            print("Stepsize: {}".format(xpoints[1] - xpoints[0]))

    print("Color: {}".format(color_name))
    print("X-label: {}".format(xlabel))
    print("Y-label: {}".format(ylabel))
    print()

    if theme == 'dark':
        mplstyle.use('dark_background')
    else:
        mplstyle.use('default')

    xvals = xpoints
    yvals = create_y_values(func, xvals)

    try:
        # Check if color is hex code
        is_hex = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', color_name)
        if not is_hex:
            colors = mcolors.cnames
            if color_name not in colors:
                print(color_name, ": Color not found.")
                color_name = 'blue'
        plt.plot(xvals, yvals, color=color_name, linewidth=2.0, linestyle=line_style)
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        plt.title(r'$ ' + func + ' $')

    except Exception:
        print("An error occured.")
    
    if file_path != "":
        plt.savefig(file_path)

    plt.grid(True)

    if not gui:
        plt.show()
    else:
        if not os.path.exists('.temp/'):
            os.mkdir('.temp/')
        plt.savefig(".temp/generated_plot.png")

    plt.cla()
    plt.clf() 
开发者ID:NITDgpOS,项目名称:PlotIt,代码行数:60,代码来源:plotutil.py

示例13: plot_line

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def plot_line(arrays, color_name, xlabel, ylabel, theme, gui, line_style, file_path):

    # Show plot summary
    print('***** Plot Summary *****')
    print('Arrays: {}'.format(arrays))
    print('Color: {}'.format(color_name))
    print('X-label: {}'.format(xlabel))
    print('Y-label: {}'.format(ylabel))

    if theme == 'dark':
        mplstyle.use('dark_background')
    else:
        mplstyle.use('default')

    try:
        # Check if color is hex code
        is_hex = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', color_name)
        if not is_hex:
            colors = mcolors.cnames
            if color_name not in colors:
                print(color_name, ": Color not found.")
                color_name = 'blue'

        # Extract numbers from X-array
        xvals = list(map(float, arrays[1:arrays.find(']')].split(',')))
        # Extract numbers from Y-array
        yvals = list(map(float,
                         arrays[arrays.find(']') + 3:len(arrays) - 1].split(',')))

        if len(xvals) == len(yvals):
            plt.plot(xvals, yvals, color=color_name, linewidth=2.0, linestyle=line_style)
            plt.savefig(file_path)
            plt.xlabel(xlabel)
            plt.ylabel(ylabel)
            plt.title(r'$ ' + 'Line:' + str(xvals) +','+ str(yvals) + ' $')
            
            if file_path != "":
                plt.savefig(file_path)
        
        else:
            print("Error: You need same number of X and Y values")

    except Exception:
        raise InvalidFunctionException('Values are improper')
    
    if file_path != "":
        plt.savefig(file_path)
    
    plt.grid(True)

    if not gui:
        plt.show()
    else:
        if not os.path.exists('.temp/'):
            os.mkdir('.temp/')
        plt.savefig(".temp/generated_plot.png")


    plt.cla()
    plt.clf() 
开发者ID:NITDgpOS,项目名称:PlotIt,代码行数:62,代码来源:plotutil.py

示例14: plot_dot

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import cnames [as 别名]
def plot_dot(xyval, color_name, xlabel, ylabel, theme, gui, dot_style, file_path):

    # Show plot summary
    print('***** Plot Summary *****')
    print('X,Y Value: {}'.format(xyval))
    print('Color: {}'.format(color_name))
    print('X-label: {}'.format(xlabel))
    print('Y-label: {}'.format(ylabel))

    if theme == 'dark':
        mplstyle.use('dark_background')
    else:
        mplstyle.use('default')

    try:
        # Check if color is hex code
        is_hex = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', color_name)
        if not is_hex:
            colors = mcolors.cnames
            if color_name not in colors:
                print(color_name, ": Color not found.")
                color_name = 'blue'

        xy=xyval.split(',')
        l=len(xy)
        #Check if even number of arguments are given
        if (l%2==0):
            #Extract x-values from xyval string
            xval=[float(xy[i]) for i in range(0,l,2)]
            #Extract y-values from xyval string
            yval=[float(xy[i]) for i in range(1,l+1,2)]
        
            plt.scatter(xval, yval, color=color_name, marker=dot_style)
            plt.savefig(file_path)
            plt.xlabel(xlabel)
            plt.ylabel(ylabel)
            plt.title(r'$ ' + xyval + ' $')

            if file_path != "":
                plt.savefig(file_path)
            
            plt.grid(True)

            if not gui:
                plt.show()
            else:
                if not os.path.exists('.temp/'):
                    os.mkdir('.temp/')
                plt.savefig(".temp/generated_plot.png")           
        else:
            print("Cannot plot odd Number of Coordinates")
        
    except Exception as e:
        print("An error occured.",e)
    
    plt.cla()
    plt.clf() 
开发者ID:NITDgpOS,项目名称:PlotIt,代码行数:59,代码来源:plotutil.py


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