Change colour of line graph once a value is reached

조회 수: 2 (최근 30일)
Dussan Radonich
Dussan Radonich 2021년 6월 19일
댓글: Dussan Radonich 2021년 6월 19일
Hello guys,
What I am trying to do is plot a line graph but when a certain value is reached I want the line to change colour just for the segment after the point was reached. The only way I found to do it is with an animation, the problem is that it is really slow and I don't care for the animation, I just want the graph to show the change in colour.
close all
clear
clc
format long g
figure('Name', 'Relative RMSD of alpha and beta structures');
clf();
hold on;
ylim([0 1]);
a = load(['12to17_alpha4.dat']);
b = load(['12to17_beta4.dat']);
title('\fontsize{16}Relative RMSD');
rel_rmsd = a./(a+b);
xseg = [a(1:end-1,1),a(2:end,1)];
yseg = [rel_rmsd(1:end-1,2),rel_rmsd(2:end,2)];
c='black';
for i=1:(length(rel_rmsd)-1)
h = plot(xseg(i,:),yseg(i,:),'-','LineWidth',1, 'color',c);
if(rel_rmsd(i,2)<0.25)
c='red';
end
if(rel_rmsd(i,2)>0.75)
c='blue';
end
drawnow;
end
This results in what I want, but like I said it is extremely slow. Especially if I have more datasets, and wanted to know if anyone knows what else I could do.
Thank you.

채택된 답변

Chunru
Chunru 2021년 6월 19일
The program is slow because it draws and updates the line segment (of two points) by segment .
To speed up in the simplest way, remove "drawnow" so that you only see the last plot, which is what you want.
If you need to further speed up the program, consider to find begining and ending of each segment (many points) of color changing and then use the plot command to plot each multipoints segments.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by