Matplotlib 基础知识——色彩篇

1.颜色与透明度

1.颜色的参数使用color或者c
2.透明度的参数使用alpha
3.在matplotlib中,我们可以使用四种定义颜色的方式,包括:
(1) 标准名,如red代表红色,yellow代表黄色;
(2) 别名,如r代表红色 (red) ,k代表黑色 (black) b代表蓝色 (blue) ;
(3) HTML十六进制字符串,如#000000代表黑色;
(4) 归一化到[0,1]的RGB元组。

x = np.array([1,2,3,4,5])
y2 = x * 2
y3 = x * 3
y4 = x * 4
y5 = x * 5

plt.plot(x,y2,color = 'r',alpha = 0.8)
plt.plot(x,y3,c = 'pink')
plt.plot(x,y4,color = '#00bc12')
plt.plot(x,y5,color = (0,0,0)) # RGB十六进制  255,255,255

2.线型:样式、线宽、线条标记

1.样式的参数名是linestyle或ls
在这里插入图片描述

x = np.array([1,2,3,4,5])

y2 = x * 2
y3 = x * 3
y4 = x * 4
y5 = x * 5

plt.plot(x,y2,linestyle = "-.")
plt.plot(x,y3,linestyle = "dashed")
plt.plot(x,y4,ls = "solid")
plt.plot(x,y5,ls= ":")

2.线宽的参数名是linewidth或lw;

x = np.array([1,2,3,4,5])

y2 = x * 2
y3 = x * 3
y4 = x * 4
y5 = x * 5

plt.plot(x,y2,ls='--',linewidth=1)
plt.plot(x,y3,ls='-',lw=3)
plt.plot(x,y4,ls=':',lw=5)
plt.plot(x,y5,ls='--',lw=7)

3.标记参数名是marker。外,我们也可以设置标记的边线颜色 (markeredgecolor or mec) 与填充色 (markerfacecolor or mfc) 等。

plt.plot(x,y2,ls='-',marker='*',markersize = 13)
plt.plot(x,y3,ls='-',marker='o',markeredgecolor='b',markerfacecolor='red')
plt.plot(x,y4,ls='-',marker='1')
plt.plot(x,y5,ls='-',marker='+',markersize = 12)

在这里插入图片描述

Marker reference: https://matplotlib.org/stable/gallery/lines_bars_and_markers/marker_reference.html
在这里插入图片描述
在这里插入图片描述

3.颜色条(colorbar)

1.在matplotlib中,颜色条 (colorbar) 是一个独立的坐标轴,可以指明图形中颜色的含义
2.可以在绘图函数(或方法)中,通过cmap参数为图形设置colorbar的配色方案(Colormap reference 至支持的颜色)。
3.创建colorbar可以通过(colorbar)函数或者Figure对象的colorbar()方法,参数基本-致: mappable是需要映射的色彩带,这个参数在colorbar方法中是必须的,但在colorbar小函数中是可选的,这是因为类MATLAB接口已经指定了Axes对象。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

常见的配色网站

1.Color Scheme Designer:https://www.chinavid.com/color.html
在这里插入图片描述

2.Colorbrewer:https://colorbrewer2.org/#type=qualitative&scheme=Set2&n=3
在这里插入图片描述

3.Adobe colorhttps://color.adobe.com/zh/create/color-wheel
在这里插入图片描述

参考:立方数据学院、《科研论文配图绘制指南》

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值