网络编程
位置:首页>> 网络编程>> Python编程>> Python可视化学习之matplotlib内置单颜色

Python可视化学习之matplotlib内置单颜色

作者:qq_21478261  发布时间:2021-07-27 06:43:46 

标签:Python,matplotlib,颜色

1、matplotlib支持的颜色格式

1.RGB 或者 RGBA 元组格式颜色

元组中浮点型数值位于 [0, 1] 之间,e.g(0.1, 0.2, 0.5) 或 (0.1, 0.2, 0.5, 0.3). RGA即Red, Green, Blue;RGBA即Red, Green, Blue, Alpha;

2.RGB or RGBA对应的hex 格式颜色

(e.g., '#0F0F0F' or '#0F0F0F0F');

3.[0,1]之间的任意浮点数

(e.g., '0.5'),其中0为纯黑色,1为白色;

4.{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}几种基本色;

5.X11/CSS4中的颜色

e.g. "blue";

6.xkcd中的颜色

e.g., 'purple (#7e1e9c)';

7.'Cn'格式颜色

matplotlib.rcParams['axes.prop_cycle']可输出所有颜色,['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'],'C0'对应'#1f77b4',依次类推;

8.Tableau 的colormap中颜色

e.g. 'tab:blue';

2、matplotlib颜色使用方法

#源自官网实例
import matplotlib.pyplot as plt
import numpy as np

t = 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),figsize=(10,5))
# 2) hex string:
ax.set_facecolor('#eafff5')
# 3) gray level string:
ax.set_title('Voltage vs. time chart', color='0.7')
# 4) single letter color string
ax.set_xlabel('time (s)', color='c')
# 5) a named color:
ax.set_ylabel('voltage (mV)', color='peachpuff')
# 6) a named xkcd color:
ax.plot(t, s, 'xkcd:crimson')
# 7) Cn notation:
ax.plot(t, .7*s, color='C4', linestyle='--')
# 8) tab notation:
ax.tick_params(labelcolor='tab:orange')
plt.show()

Python可视化学习之matplotlib内置单颜色

3、matplotlib内置单颜色色号

matplotlib内置的颜色可以使用matplotlib.colors 调用,有'BASE_COLORS','TABLEAU_COLORS','CSS4_COLORS'及 'XKCD_COLORS'四类。使用matplotlib.colors.类名称可输出颜色号。

'BASE_COLORS'色号

b    (0, 0, 1)
g    (0, 0.5, 0)
r    (1, 0, 0)
c    (0, 0.75, 0.75)
m    (0.75, 0, 0.75)
y    (0.75, 0.75, 0)
k    (0, 0, 0)
w    (1, 1, 1)

'BASE_COLORS' *  

Python可视化学习之matplotlib内置单颜色

TABLEAU_COLORS色号

tab:blue    #1f77b4
tab:orange    #ff7f0e
tab:green    #2ca02c
tab:red    #d62728
tab:purple    #9467bd
tab:brown    #8c564b
tab:pink    #e377c2
tab:gray    #7f7f7f
tab:olive    #bcbd22
tab:cyan    #17becf

TABLEAU_COLORS *  

Python可视化学习之matplotlib内置单颜色

CSS4_COLORS色号

共计148种颜色。 

颜色名称    hex色号
aliceblue    #F0F8FF
antiquewhite    #FAEBD7
aqua    #00FFFF
aquamarine    #7FFFD4
azure    #F0FFFF
beige    #F5F5DC
bisque    #FFE4C4
black    #000000

CSS4_COLORS *  

Python可视化学习之matplotlib内置单颜色

XKCD_COLORS色号

共计949种色号。

xkcd:cloudy blue    #acc2d9
xkcd:dark pastel green    #56ae57
xkcd:dust    #b2996e
xkcd:electric lime    #a8ff04
xkcd:fresh green    #69d84f
xkcd:light eggplant    #894585
xkcd:nasty green    #70b23f
xkcd:really light blue    #d4ffff

XKCD_COLORS *

Python可视化学习之matplotlib内置单颜色

Python可视化学习之matplotlib内置单颜色

来源:https://blog.csdn.net/qq_21478261/article/details/106969074

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com