line matlab color,绘制彩色线图

Beautiful and distinguishable line colors + colormap

The default Matlab default line spec and colormaps are astoundingly crude. This function creates distinguishable colors by spacing them out ~equally in *perceptive* space, not in RGB space. It is based off the research of professor Cynthia Brewer (colorbrewer!) but amazingly easy to use.

This function creates an Nx3 array of N [R B G] colors

These can be used to plot lots of lines with distinguishable and nice looking colors.

lineStyles = linspecer(N); makes N colors for you to use: lineStyles(ii,:)

colormap(linspecer); set your colormap to have easily distinguishable colors and a pleasing aesthetic

lineStyles = linspecer(N,'qualitative'); forces the colors to all be distinguishable (up to 12)

lineStyles = linspecer(N,'sequential'); forces the colors to vary along a spectrum

_______________________________________________

Examples demonstrating the colors.

% LINE COLORS

N=6;

X = linspace(0,pi*3,1000);

Y = bsxfun(@(x,n)sin(x+2*n*pi/N), X.', 1:N);

C = linspecer(N);

axes('NextPlot','replacechildren', 'ColorOrder',C);

plot(X,Y,'linewidth',5)

ylim([-1.1 1.1]);

% SIMPLER LINE COLOR EXAMPLE

N = 6; X = linspace(0,pi*3,1000);

C = linspecer(N)

hold off;

for ii=1:N

Y = sin(X+2*ii*pi/N);

plot(X,Y,'color',C(ii,:),'linewidth',3);

hold on;

end

% COLORMAP EXAMPLE

A = rand(15);

figure; imagesc(A); % default colormap

figure; imagesc(A); colormap(linspecer); % linspecer colormap

_______________________________________________

Credits and where the function came from:

The colors are largely taken from:

http://colorbrewer2.org and Cynthia Brewer, Mark Harrower and The Pennsylvania State University

She studied this from a phsychometric perspective and crafted the colors

beautifully.

I made choices from the many there to decide the nicest once for plotting lines in Matlab. I also made a small change to one of the colors I thought was a bit too bright. In addition some interpolation is going on for the sequential line styles. An Apache-Style Software License is included in the file.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Matlab可以使用`boxplot`函数来画带均值的箱线图。箱线图是一种用于展示数据分布和异常值的可视化方法。 下面是使用Matlab绘制带均值的箱线图的步骤: 1. 准备数据:将需要绘制线图的数据准备好,可以是一个向量或者一个矩阵。 2. 调用`boxplot`函数:使用`boxplot`函数来绘制线图。函数的基本语法如下: ```matlab boxplot(data, 'Labels', labels, 'Whisker', whisker_value) ``` - `data`是需要绘制线图的数据,可以是一个向量或者一个矩阵。 - `Labels`是一个可选参数,用于指定每个箱线图的标签。 - `Whisker`是一个可选参数,用于指定箱线图的须长度,默认值为1.5。 3. 添加均值线:计算数据的均值,并使用`line`函数在箱线图上添加均值线。函数的基本语法如下: ```matlab line([x_start, x_end], [mean_value, mean_value], 'Color', 'r', 'LineWidth', line_width) ``` - `x_start`和`x_end`是均值线的起始和结束位置,可以根据需要进行调整。 - `mean_value`是数据的均值。 - `'Color'`参数用于指定均值线的颜色,这里设置为红色。 - `'LineWidth'`参数用于指定均值线的宽度。 下面是一个示例代码,演示如何使用Matlab绘制带均值的箱线图: ```matlab % 准备数据 data = [randn(100,1)*2+10; randn(50,1)*3+5]; % 绘制线图 boxplot(data, 'Whisker', 1.5) % 计算均值 mean_value = mean(data); % 添加均值线 line([0.75, 1.25], [mean_value, mean_value], 'Color', 'r', 'LineWidth', 2) % 设置图像标题和坐标轴标签 title('带均值的箱线图') xlabel('数据') ylabel('值') ``` 希望对你有帮助!如果有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值