필터 지우기
필터 지우기

I want to color for $\eta<1.054288$ by blue and red for, $\eta>1.054288$ of a curve from data

조회 수: 1 (최근 30일)
I want to use two colors of a single curve obtained from the data. I want to make the curve color
  • blue for $0.608130<\eta<1.054288$ in the upper portion of the curve only
  • red for $\eta>1.054288$ in the upper portion of the curve only
  • blue for $\eta>0.608130$ i.e the total lower portion of the curve only
How to change the color of the curve accordingly.
clear all
format long
set(0,'DefaultAxesFontSize',20);
figure;
load('EP_EP(1).mat')
plot(x(3,:),x(1,:),'b', 'LineWidth',2)
hold on
load('EP_EP(2).mat')
plot(x(3,:),x(1,:),'b', 'LineWidth',2)
xlabel('$\eta\rightarrow$','FontSize',20,'interpreter','latex')
ylabel('$x\rightarrow$','FontSize',20,'interpreter','latex')
xline(1.054288,'k', 'LineWidth',2)
xline(0.608130,'k', 'LineWidth',2);
axis([.4 1.5 0 .6]);

채택된 답변

Star Strider
Star Strider 2023년 5월 14일
편집: Star Strider 2023년 5월 14일
This is a bit more involved than it might otherwise seem, because simply using logical indexing to define the red line creates a ‘bridging’ red line at the threshold value. Creating ‘v1’ and ‘v2’ avoids that problem, and provides (what I believe to be) the desired result.
Try this —
clear all
format long
set(0,'DefaultAxesFontSize',20);
figure;
LD1 = load('EP_EP(1).mat');
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>curve_func
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>defaultprocessor
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>options
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>jacobian
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>hessians
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>testf
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>userf
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>process
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>singmat
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>locate
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>init
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>done
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>adapt
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>fun_eval
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>jacobian
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>jacobianp
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>hessians
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>hessiansp
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>der3
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\GUI\ComputationConfigurations\ContCurve.m>@(dat)loaderfunction(dat)
x1 = LD1.x;
LD2 = load('EP_EP(2).mat');
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>curve_func
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>defaultprocessor
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>options
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>jacobian
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>hessians
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>testf
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>userf
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>process
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>singmat
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>locate
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>init
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>done
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Equilibrium\equilibrium.m>adapt
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>fun_eval
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>jacobian
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>jacobianp
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>hessians
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>hessiansp
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\Systems\Gourav_new9.m>der3
Warning: Could not find appropriate function on path loading function handle F:\1. Research\2. Mathematical Biology\MatCont7p4\MatCont7p4\GUI\ComputationConfigurations\ContCurve.m>@(dat)loaderfunction(dat)
x2 = LD2.x;
thld = 1.054288;
x1b = x1(3,:) < thld;
ixt = find(diff(sign(x1(3,:)-thld)));
v1 = 1:ixt(1);
v2 = ixt(2):numel(x1(3,:));
x2b = x2(3,:) < thld;
figure
plot(x1(3,x1b),x1(1,x1b),'b', 'LineWidth',2)
hold on
plot(x2(3,x2b),x2(1,x2b),'b', 'LineWidth',2)
plot(x1(3,v1),x1(1,v1),'r', 'LineWidth',2)
plot(x1(3,v2),x1(1,v2),'b', 'LineWidth',2)
plot(x2(3,~x2b),x2(1,~x2b),'r', 'LineWidth',2)
xlabel('$\eta\rightarrow$','FontSize',20,'interpreter','latex')
ylabel('$x\rightarrow$','FontSize',20,'interpreter','latex')
xline(1.054288,'k', 'LineWidth',2)
xline(0.608130,'k', 'LineWidth',2);
axis([.4 1.5 0 .6]);
EDIT — (14 May 2023 at 16:18)
Plot changed following posted clarification.
.
  댓글 수: 5
Atom
Atom 2023년 5월 15일
Thanks. What is the meaning of
ixt = find(diff(sign(x1(3,:)-thld)));
Star Strider
Star Strider 2023년 5월 15일
I thought I explained that earlier. I apparently wasn’t clear.
That finds the approximate indices of the points where ‘x1(3,:)’ crosses the ‘thld’ (threshold) value. There are two, and those values are then used to define index vectors ‘v1’ and ‘v2’ that define the two desired segments of ‘x1’.
I initially created them to avoid the ‘bridging’ red line that otherwise parallels the first yline call, however after I read the clarification, using them to create the desired plot only involved changing the colour of the part of the line that ‘v2’ indexes to blue.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Shaik
Shaik 2023년 5월 14일
Hi Atom,
To change the color of the curve based on specific conditions, you can use the plot function multiple times with different segments of the data and different colors. Here's an updated code snippet that demonstrates how to achieve this:
clear all
format long
set(0,'DefaultAxesFontSize',20);
figure;
load('EP_EP(1).mat')
xdata = x(3,:);
ydata = x(1,:);
% Plot the upper portion of the curve in blue for 0.608130 < eta < 1.054288
upper_blue_indices = xdata > 0.608130 & xdata < 1.054288;
plot(xdata(upper_blue_indices), ydata(upper_blue_indices), 'b', 'LineWidth', 2)
hold on
% Plot the upper portion of the curve in red for eta > 1.054288
upper_red_indices = xdata > 1.054288;
plot(xdata(upper_red_indices), ydata(upper_red_indices), 'r', 'LineWidth', 2)
% Plot the lower portion of the curve in blue for eta > 0.608130
lower_blue_indices = xdata <= 0.608130;
plot(xdata(lower_blue_indices), ydata(lower_blue_indices), 'b', 'LineWidth', 2)
xlabel('$\eta\rightarrow$','FontSize',20,'interpreter','latex')
ylabel('$x\rightarrow$','FontSize',20,'interpreter','latex')
xline(1.054288, 'k', 'LineWidth', 2)
xline(0.608130, 'k', 'LineWidth', 2);
axis([.4 1.5 0 .6]);

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by