필터 지우기
필터 지우기

How to decide the color on the legend

조회 수: 4 (최근 30일)
Francesco Guaresi
Francesco Guaresi 2018년 12월 29일
댓글: Francesco Guaresi 2019년 1월 2일
Hi guys! I want to plot 2 lines at each time (for 5 times) on the same plot, so I want to choose the color. I wrote the code in this way:
N = 5;
col=hsv(N); %colors figure
for i=1:N
mtot_h = 2000+i*500-500; % [kg/h]
mtot = mtot_h/3600; % [kg/s]
minlet = [2/3*mtot 0 0 0 0 1/3*mtot]; % inlet mass flow rates [kg/s]
Fi0 = minlet./MWi; % [mol/s]
inlet = [Fi0 Tin TweFirstGuess Pin];
M = eye(9); M(8,8)=0;
options = odeset('Mass',M,'RelTol',1E-8,'AbsTol',1E-12);
[z,outlet] = ode15s(@PFR,[0 L],inlet,options);
FC3H8 = outlet(:,1); % [mol/s]
...
figure(1)
hold on
plot(z,T-273.15,z,Twe-273.15,'Color',col(i,:))
refline(0,Tmax) % horizzontal line at T=1100°C
xlabel 'Reactor length [m]', ylabel 'Temperature [°C]', title 'Temperature profiles'
legendInfo{i} = ['Mtot: ' num2str(mtot_h) ' kg/h'];
legendInfo{i+1} = 'T max';
legend(legendInfo,'Location','southeast')
end
With the command "color" inside the plot I can choose the color of each line, but when it shows the legend, the legend has different colors! How can I choose the colors inside the legend?

답변 (1개)

madhan ravi
madhan ravi 2018년 12월 29일
편집: madhan ravi 2018년 12월 29일
I am not certain what you want but try this example:
c={'r','g','m','k','b'}; % store the colors option in a cell array
for i =1:5
plot(rand(1,10),c{i}) % selects unique color for each iteration
hold on
end
  댓글 수: 3
madhan ravi
madhan ravi 2019년 1월 2일
Because you were using the same colours for the two datas , try the below:
plot(z,T-273.15,'Color',col(end-i+1,:))
hold on
plot(z,Twe-273.15,'Color',col(i,:))
Note: I don't recommend using globals parameterize your function instead.
Francesco Guaresi
Francesco Guaresi 2019년 1월 2일
But in this way it changes the colors of lines from the first plot

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

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by