python中定义的颜色

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中定义的颜色)