How to colour a portion of a curve by red and remaining by black

1 回表示 (過去 30 日間)
Atom
Atom 2024 年 6 月 6 日
コメント済み: Voss 2024 年 6 月 7 日
I want to colour the lower portion of curve by red and broked curve and upper part of the curve by black as shown in the fig attached.
Code
clear all
format long
set(0,'DefaultAxesFontSize',20);
figure
load('EP_EP(1).mat','x'); %load only x
idx = x(3,:)>=0.16 & x(3,:)<=0.305003;
plot(x(3,:),x(1,:),'k--', 'LineWidth',2);
xlabel('$a$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k');
ylabel('$b$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k');
axis([0 .4 .3 1]);

採用された回答

Voss
Voss 2024 年 6 月 6 日
編集済み: Voss 2024 年 6 月 6 日
set(0,'DefaultAxesFontSize',20);
figure
load('EP_EP(1).mat','x'); %load only x
[~,idx] = max(x(3,:));
plot(x(3,idx:end),x(1,idx:end),'k', 'LineWidth',2); % solid black line
hold on
plot(x(3,1:idx),x(1,1:idx),'r--', 'LineWidth',2); % broken red line
xlabel('$a$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k');
ylabel('$b$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k');
axis([0 .4 .3 1]);
  6 件のコメント
Atom
Atom 2024 年 6 月 7 日
Thank you, Voss, for your support. I greatly appreciate your time and effort. My regards.
Voss
Voss 2024 年 6 月 7 日
You're welcome!

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2024 年 6 月 6 日
Plot it as TWO curves, both on the same figure, one in red, one in black.
Use the hold command between the two calls to plot, so the two curves will be on the same figure.
  2 件のコメント
Atom
Atom 2024 年 6 月 6 日
How to do that modification.... I need some assistance with modifying the code. Thanks a lot.
Voss
Voss 2024 年 6 月 6 日

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by