Azzera filtri
Azzera filtri

How to decide the color on the legend

4 visualizzazioni (ultimi 30 giorni)
Francesco Guaresi
Francesco Guaresi il 29 Dic 2018
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?

Risposte (1)

madhan ravi
madhan ravi il 29 Dic 2018
Modificato: madhan ravi il 29 Dic 2018
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 Commenti
madhan ravi
madhan ravi il 2 Gen 2019
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 il 2 Gen 2019
But in this way it changes the colors of lines from the first plot

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by