How to decide the color on the legend
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!