南京城市规划建设展览馆网站,凤凰一级a做爰片免费网站,龙岩 网站建设,跨境电商多平台运营详解matplotlib的color配置
Matplotlib可识别的color格式
格式举例RGB或RGBA#xff0c;由[0, 1]之间的浮点数组成的元组#xff0c;分别代表红色、绿色、蓝色和透明度(0.1, 0.2, 0.5), (0.1, 0.2, 0.5, 0.3不区分大小写的十六进制RGB或RGBA字符串。‘#0f0f0f’, ‘#0f0f0f…详解matplotlib的color配置
Matplotlib可识别的color格式
格式举例RGB或RGBA由[0, 1]之间的浮点数组成的元组分别代表红色、绿色、蓝色和透明度(0.1, 0.2, 0.5), (0.1, 0.2, 0.5, 0.3不区分大小写的十六进制RGB或RGBA字符串。‘#0f0f0f’, ‘#0f0f0f80’不区分大小写的RGB或RGBA字符串等效的十六进制缩写重复字符。‘#abc’ 等于 ‘#aabbcc’对于灰度值浮点值在闭合区间[0,1]中的字符串表示形式。‘0’ 表示黑色‘1’表示白色‘0.8’表示浅灰色一些基本颜色的单字符简写符号。‘b’表示蓝色不区分大小写的X11/CSS4颜色名称不包含空格。‘aquamarine’使用前缀’xkcd:进行xkcd颜色调查颜色名称不区分大小写。‘xkcd:sky blue’来自T10分类调色板的不区分大小写的Tableau颜色。‘tab:blue’CN颜色规范其中C排在一个数字前面作为默认属性cycle的索引‘C0’
import matplotlib.pyplot as plt
import numpy as npt np.linspace(0.0, 2.0, 201)
s np.sin(2 * np.pi * t)# 1) RGB tuple:
fig, ax plt.subplots(facecolor(.18, .31, .31))
# 2) hex string:
ax.set_facecolor(#eafff5)
# 3) gray level string:
ax.set_title(Voltage vs. time chart, color0.7)
# 4) single letter color string
ax.set_xlabel(Time [s], colorc)
# 5) a named color:
ax.set_ylabel(Voltage [mV], colorpeachpuff)
# 6) a named xkcd color:
ax.plot(t, s, xkcd:crimson)
# 7) Cn notation:
ax.plot(t, .7*s, colorC4, linestyle--)
# 8) tab notation:
ax.tick_params(labelcolortab:orange)plt.show()通过辅助函数认识颜色
import mathfrom matplotlib.patches import Rectangle
import matplotlib.pyplot as plt
import matplotlib.colors as mcolorsdef plot_colortable(colors, *, ncols4, sort_colorsTrue):cell_width 212cell_height 22swatch_width 48margin 12# Sort colors by hue, saturation, value and name.if sort_colors is True:names sorted(colors, keylambda c: tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(c))))else:names list(colors)n len(names)nrows math.ceil(n / ncols)width cell_width * 4 2 * marginheight cell_height * nrows 2 * margindpi 72fig, ax plt.subplots(figsize(width / dpi, height / dpi), dpidpi)fig.subplots_adjust(margin/width, margin/height,(width-margin)/width, (height-margin)/height)ax.set_xlim(0, cell_width * 4)ax.set_ylim(cell_height * (nrows-0.5), -cell_height/2.)ax.yaxis.set_visible(False)ax.xaxis.set_visible(False)ax.set_axis_off()for i, name in enumerate(names):row i % nrowscol i // nrowsy row * cell_heightswatch_start_x cell_width * coltext_pos_x cell_width * col swatch_width 7ax.text(text_pos_x, y, name, fontsize14,horizontalalignmentleft,verticalalignmentcenter)ax.add_patch(Rectangle(xy(swatch_start_x, y-9), widthswatch_width,height18, facecolorcolors[name], edgecolor0.7))return fig基本色
plot_colortable(mcolors.BASE_COLORS, ncols3, sort_colorsFalse)表盘色
plot_colortable(mcolors.TABLEAU_COLORS, ncols2, sort_colorsFalse)CSS颜色
plot_colortable(mcolors.CSS4_COLORS)
plt.show()XKCD颜色
xkcd_fig plot_colortable(mcolors.XKCD_COLORS)
xkcd_fig.savefig(XKCD_Colors.png)matplotlib.colors API 点击进入