Changing color of graphs in MATLAB plot
34 ビュー (過去 30 日間)
古いコメントを表示
Hans123
2019 年 6 月 21 日
回答済み: Korosh Agha Mohammad Ghasemi
2020 年 12 月 7 日
I have a basic plot command that is in a loop, and each iteration spits out a graph on the same figure.
There would be about 7000+ plots overlayed on the same figure. I do not inted to use legend, rather I want to use the jet colormap to show the order.
how can I include the jet colormap function in the below command that plots the graphs
plot(timevals,B{k}(:,2),'LineWidth',1.1)
The current figure I get for about 10 iterations is that, I want consitent color changes
0 件のコメント
採用された回答
Star Strider
2019 年 6 月 21 日
With 7000+ curves, it is unlikely that you are going to be able to distinguish them regardless of the colormap you use.
I would instead use plot3, and offset them slightly in the x-direction, leaving the others unchanged.
Example:
data = rand(5, 20); % Data Vector Matrix
t = linspace(0, 1, size(data,2)); % Time Vector Matrix
x = (0:size(data,1)-1)' * ones(1,size(data,2)); % Offset Vector Matrix
figure
plot3(x, t, data)
grid on
3 件のコメント
Star Strider
2019 年 6 月 21 日
As always, my pleasure.
You are still not going to be able to distinguisn 700 curves, and even 70 are going to be a challenge.
With 70 curves, distinguishing the colormap will be easier.
Apparently, it is only possible to specify one color per line object, so a loop is the only way I can find to do what you want:
cm = colormap(jet(70));
data = exp(-(0:199)/150)+randn(70, 200)*0.01; % Data Vector Matrix
t = linspace(0, 1, size(data,2)); % Time Vector Matrix
x = (0:size(data,1)-1)' * ones(1,size(data,2)); % Offset Vector Matrix
figure
hold all
for k = 1:size(data,1)
plot3(t, x(k,:), data(k,:), 'Color',cm(k,:));
end
hold off
grid on
view(30,30)
xlabel('Time')
This is for 70 curves. Make the appropriate changes for different numbers of them.
その他の回答 (1 件)
Korosh Agha Mohammad Ghasemi
2020 年 12 月 7 日
%https://zil.ink/korosh -------- Ways to contact me ----------
% Korosh Agha Mohammad Ghasemi !
% Chemical Engineering at Shiraz University
x=linspace(0,2,100);
figure;
for a=[0.1 0.5 1 2 4]
y=x.^a; %The function is hypothetical
if a == 0.1 %Any color can be substituted
y=x.^a;
plot(x,y,'k') %Now choose the color
hold on
elseif a == 0.5
y=x.^a;
plot(x,y,'b') %Now choose the color
hold on
elseif a==1
y=x.^a;
plot(x,y,'g') %Now choose the color
hold on
elseif a==2
y=x.^a;
plot(x,y,'r') %Now choose the color
hold on
elseif a==4
y=x.^a;
plot(x,y,'y') %Now choose the color
hold on
grid on
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Colormaps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!