How to plot multiple plots using the same colour in a figure

조회 수: 62 (최근 30일)
Samantha Sim
Samantha Sim 2019년 9월 30일
답변: Alexandra McClernon Ownbey 2019년 9월 30일
I have a set of data. Within this data, I need to plot the selected data if those data satisfy some conditions. First, I use for loop to run through the whole data set then, I use another for loop and if loop to filter and get the data that satisfy the conditions. Within the if loop, I plot the data that was filtered, hold on the plot until the whole set of data is ploted. But when I plot it, they are of different colours, how do I make multiple plots in a figure to be in the same colour.

답변 (1개)

Alexandra McClernon Ownbey
Alexandra McClernon Ownbey 2019년 9월 30일
You get the color that is used on the first plot and then use the same color for other plots.
% random x and y values
x = rand(10);
y = x.^2-5;
figure()
p = plot(x(:,1),y(:,1));
c = p.Color;
hold on
% plot rest of the data set
for i = 2:length(x)
plot(x(:,i),y(:,i),'Color',c)
end

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by