美文网首页
python中定义的颜色

python中定义的颜色

作者: estate47 | 来源:发表于2021-02-23 11:36 被阅读0次

    1.可以再网页上查找自己想要的颜色代码:

    https://m.wang1314.com/doc/webapp/topic/21084865.html
    

    2.显示颜色的代码如下:

    import matplotlib.pyplot as plt
    import matplotlib.patches as patches
    import matplotlib.colors as colors
    import math
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    ratio = 1.0 / 3.0
    count = math.ceil(math.sqrt(len(colors.cnames)))
    x_count = count * ratio
    y_count = count / ratio
    x = 0
    y = 0
    w = 1 / x_count
    h = 1 / y_count
    
    for c in colors.cnames:
        pos = (x / x_count, y / y_count)
        ax.add_patch(patches.Rectangle(pos, w, h, color=c))
        ax.annotate(c, xy=pos)
        if y >= y_count - 1:
            x += 1
            y = 0
        else:
            y += 1
    
    plt.show()
    

    显示如图:

    image

    相关文章

      网友评论

          本文标题:python中定义的颜色

          本文链接:https://www.haomeiwen.com/subject/gznqxltx.html