Legend doesn't have colors

I'm trying to make a plot that has mutliple lines, and the plot works fine and each line is a different color, but the legend does not showing which value goes with which line. Any help on this would be appreciated. Here is my code and the plot:
clc; clear;
%
% Given:
% Surface
L = 4/1000; % thickness of the glass, m
k = 1.4; % thermal conductivity of glass, W/m-K
T_si = 15; % inner surface temperature, oC
%
% Air inside
T_inf_i = 25; % air temperature ouside, oC
hi = 10; % convection heat trasnfer coefficient, W/m^2-K
%
% Air outside
T_inf_o = -10; % air temperature inside, oC
ho = 65; % convection heat trasnfer coefficient, W/m^2-K
%
% Calculate thermal resistances
R_conv_i = 1/hi; % inside convection resistance
R_cond = L/k; % conduction resistance
%
% Variables
ho_values = [2 20 65 100];
T_inf_o_range = -30:1:30;
%
% Initialize matrix to store power requirements
power_req = zeros(length(ho_values), length(T_inf_o_range));
%
% Loop over h_o values
for i = 1:length(ho_values)
ho = ho_values(i);
%
% Calculate outside convection resistance
R_conv_o = 1/ho;
%
% Loop over T_inf_o values
for j = 1:length(T_inf_o_range)
T_inf_o = T_inf_o_range(j);
% Calculate total thermal resistance
R_total = R_conv_i + R_cond + R_conv_o;
% Calculate heat flux
q = (T_si - T_inf_o) / R_total;
% Store power requirement
power_req(i, j) = q;
end
end
%
% Plot power requirement as a function of T_inf_o for each h_o
hold on
for i = 1:length(ho_values)
plot(T_inf_o_range, power_req(i, :))
end
xlabel('T_{\infty, o} (^oC)')
ylabel('Power Requirement (W/m^2)')
legend('ho = 2', 'ho = 20', 'ho = 65', 'ho = 100')
hold off

4 commentaires

the cyclist
the cyclist le 15 Fév 2024
I've formatted and run your code here. I don't quite understand the problem you are describing.
Mitchell Terry
Mitchell Terry le 15 Fév 2024
Modifié(e) : Mitchell Terry le 15 Fév 2024
on my end, the legend doesn't have any color. Is there a possible setting I need to change?
Walter Roberson
Walter Roberson le 15 Fév 2024
When we run the code here, legend() has color.
Mitchell Terry
Mitchell Terry le 15 Fév 2024
Mine doesn't though

Connectez-vous pour commenter.

Réponses (1)

Mitchell Terry
Mitchell Terry le 15 Fév 2024
Déplacé(e) : Dyuman Joshi le 15 Fév 2024

0 votes

Hello, I have figured it out, it was because my linewidth was too small. Thank you for your help!

2 commentaires

the cyclist
the cyclist le 15 Fév 2024
Déplacé(e) : Dyuman Joshi le 15 Fév 2024
Glad you figured it out.
Adam Danz
Adam Danz le 16 Fév 2024
Modifié(e) : Adam Danz le 16 Fév 2024
What was your linewidth values? If the lines appeared in the axes, they should have appeared in the legend.

Connectez-vous pour commenter.

Produits

Version

R2023b

Tags

Modifié(e) :

le 16 Fév 2024

Community Treasure Hunt

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

Start Hunting!

Translated by