2017-02-11 263 views

答えて

2

あなたはMATLAB R2014b以降を持っている場合、これは難しいことではありません。その結果

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) 

は:

enter image description here

Undocumented Features - Color-coded 2D line plots with color data in third dimensionより抜粋します。元の著者はthewaywewalkでした。アトリビューションの詳細はcontributor pageにあります。ソースはCC BY-SA 3.0でライセンスされており、Documentation archiveにあります。参照トピックID:2383およびID:7849を参照してください。

+0

ソリューションをありがとう! –

1

ここでは、可能なアプローチがあります。線の各セグメントを、希望のカラーマップとは異なる色で明示的にプロットします。

x = 1:10; % x data. Assumed to be increasing 
y = x.^2; % y data 
N = 100; % number of colors. Assumed to be greater than size of x 
cmap = parula(N); % colormap, with N colors 
linewidth = 1.5; % desired linewidth 
xi = x(1)+linspace(0,1,N+1)*x(end); % interpolated x values 
yi = interp1(x,y,xi); % interpolated y values 
hold on 
for n = 1:N 
    plot(xi([n n+1]), yi([n n+1]), 'color', cmap(n,:), 'linewidth', linewidth); 
end 

enter image description here

+1

ありがとう、@ルイスメンド! –

関連する問題