How to colour a portion of a curve by red and remaining by black
조회 수: 1 (최근 30일)
이전 댓글 표시
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. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1710536/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1710536/image.jpeg)
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]);
댓글 수: 0
채택된 답변
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]);
추가 답변 (1개)
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!