Matlab中的2D线条渐变色彩 [英] 2-D line gradient color in Matlab

查看:267
本文介绍了Matlab中的2D线条渐变色彩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Matlab中为2D线添加渐变颜色,特别是当您的数据点数少(小于10?)时,所以结果将类似于下图中的一个?



解决方案

这是如果你有MATLAB R2014b或更新的话,这并不难。


x = linspace(-10,10,n); y = x。^ 2;
p = plot(x,y,'r','LineWidth',5);

%修改jet-colormap
cd = [uint8(jet(n)* 255)uint8(ones(n,1))]';

drawnow
set(p.Edge,'ColorBinding','interpolated','ColorData',cd)

其结果如下:





摘自未记录的特征 - 带三维颜色数据的彩色编码二维线图。原作者是 thewaywewalk 。可以在撰稿人处找到归因详情页面。该源根据 CC BY-SA 3.0 进行许可,可在< a href =https://archive.org/details/documentation-dump.7z =nofollow noreferrer>文档档案。参考主题ID:2383和示例ID:7849。


Is it possible to add gradient color to 2-D line in Matlab, especially when you have small number of data points (less than 10?), so the result would be similar to one in image below?

解决方案

This is not difficult if you have MATLAB R2014b or newer.

n = 100;
x = linspace(-10,10,n); y = x.^2;
p = plot(x,y,'r', 'LineWidth',5);

% modified jet-colormap
cd = [uint8(jet(n)*255) uint8(ones(n,1))].';

drawnow
set(p.Edge, 'ColorBinding','interpolated', 'ColorData',cd)

Which results in:

Excerpted from Undocumented Features - Color-coded 2D line plots with color data in third dimension. The original author was thewaywewalk. Attribution details can be found on the contributor page. The source is licenced under CC BY-SA 3.0 and may be found in the Documentation archive. Reference topic ID: 2383 and example ID: 7849.

这篇关于Matlab中的2D线条渐变色彩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆