How can I create a gradient of 255 line plots?

27 ビュー (過去 30 日間)
Alexander Carlberg
Alexander Carlberg 2018 年 11 月 6 日
回答済み: Simon Dengler 2022 年 11 月 29 日
I am plotting many lines on a single plot but too many to manually give each line a specific color. I need to create a gradient of these lines (each line representing a different time point) to show that the lines gradually shift down. I figured out how to create a gray gradient but can't figure out how to create a color gradient. This is the command written for the gray gradient and attached an image of what it looks like. % sheet=1 DataZ=csvread(trimname,sheet) % plotsize=size(DataZ,2) Frequency=DataZ(:,1) %hours Zimpedance=DataZ(:,2:plotsize) LogZ=log10(Zimpedance) contour(LogZ) mesh(LogZ) % get(gca,'ColorOrder') N = plotsize; C = repmat(linspace(1,0.1,N).',1,3); axes('ColorOrder',C,'NextPlot','replacechildren') plot(log10(Frequency),LogZ) title('60C Harr/DI 0V PE') xlabel('Log Frequency (Hz)') ylabel('Log Z (Ohm)')

回答 (2 件)

Akira Agata
Akira Agata 2018 年 11 月 7 日
I think the solution would be like this. In this example, like color changes as the y-intercept of the like decrease.
% Gradually shifting lines data
% "plot(Frequency,Data(:,k))" shows k-th line
yIntercept = 10*exp(-0.05*(1:100));
Data = repmat(linspace(2,1)',1,100);
Data = Data + yIntercept;
Frequency = linspace(1,2)';
% Set color vector
c = parula(100);
% Visualize the result
figure
hold on
for kk = 1:100
plot(Frequency,Data(:,kk),'Color',c(kk,:))
end
box on
  3 件のコメント
Akira Agata
Akira Agata 2018 年 11 月 9 日
Please replace 'Set color vector' section in the above script as follows. In this case, the total number of line is assumed to 100.
% Set color vector
cStart = uisetcolor([1 0.8 0.8],'Select a start color');
cEnd = uisetcolor([0.8 0.0 0],'Select an end color');
c = interp1([1;100],[cStart;cEnd],(1:100)');
AnaelG
AnaelG 2020 年 3 月 4 日
Now is there an elegant way to do that (without a for loop) ? :D

サインインしてコメントする。


Simon Dengler
Simon Dengler 2022 年 11 月 29 日
I'm using
colororder([jet(44)])
for similar functionality

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by