来源

使用matlab进行数据绘图,经常使用不同颜色表示不同曲线,但是帮助文档中的有写曲线颜色打印出来并不是很明显,此处整理我自己使用的颜色。

总体方针

在网上搜索 “RGB颜色表” ,然后挑选适合的颜色。此处推荐一个我自己经常使用的网站:华艺美术制作

使用colormap

使用现成的颜色序列 colormap获取颜色矩阵,然后在绘制曲线图的时候赋值到 color属性中。
Beautiful and distinguishable line colors + colormap 提供了综合后的函数, 也可以使用matlab自带的colormap,如下图。Colormap Name也是函数可以直接调用,比如 parula

x = 0:0.01:2*pi;

f = figure('Position', [10 50 600 400]);
hold on;
C = parula(7);
plot(sin(x),        'LineWidth', 1.5, 'Color', C(1, :))
hold on
plot(sin(x+pi/6),   'LineWidth', 1.5, 'Color', C(2, :))
plot(sin(x+2*pi/6), 'LineWidth', 1.5, 'Color', C(3, :))
plot(sin(x+3*pi/6), 'LineWidth', 1.5, 'Color', C(4, :))
plot(sin(x+4*pi/6), 'LineWidth', 1.5, 'Color', C(5, :))
plot(sin(x+5*pi/6), 'LineWidth', 1.5, 'Color', C(6, :))
plot(sin(x+6*pi/6), 'LineWidth', 1.5, 'Color', C(7, :))

此外, Generate maximally perceptually-distinct colors也提供了一个不同 colormap 设置下线条的对比。

matlab二维图默认的是 lines 这个配色。更改这个默认配色的代码如下

更改默认绘图颜色序列

figure
ax = gca;
newDefaultColors = colorcube(10);	% 参数表示返回多少种颜色
set(ax, 'ColorOrder', newDefaultColors, 'NextPlot', 'replacechildren');
% 此处推荐把上面设置样式语句放在 hold on等前面,
hold on; box on; grid on;

在这里插入图片描述

使用单个colormap颜色绘图

linspecer函数中获取颜色序列

C = linspecer(10);			% 这个函数链接在前面提到了
plot(Fx, 'LineWidth', 1, 'Color', C(1,:));	% 直接使用颜色

% 也可以修改默认颜色
set(gca, 'ColorOrder', C, 'NextPlot', 'replacechildren');
hold on; box on; grid on;

最近发现一个更喜欢的matlab函数:Generate maximally perceptually-distinct colors。 个人感觉这个函数的对比度更明显。

使用 coloroder

x = 0:0.01:2*pi;

f = figure('Position', [10 50 600 400]);
hold on;
C = parula(7);
newcolors = [0.83 0.14 0.14
             1.00 0.54 0.00
             0.47 0.25 0.80
             0.25 0.80 0.54];
         
colororder(newcolors)

plot(sin(x),        'LineWidth', 1.5)
hold on
plot(sin(x+pi/6),   'LineWidth', 1.5)
plot(sin(x+2*pi/6), 'LineWidth', 1.5)
plot(sin(x+3*pi/6), 'LineWidth', 1.5)

颜色

有几个颜色的网站补上。
可以直接点击颜色进行复制:
链接零
链接一
链接二
链接三
链接四

1
2

在这里插入图片描述

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐