Plotting Lines of Different Colors

4 ビュー (過去 30 日間)
Jeremy
Jeremy 2011 年 2 月 2 日
I'm plotting the thermal efficiency vs. pressure ratio of an engine based on varying pressure ratio and turbine inlet temperature. I'm coming up with multiple lines of constant temperature on my plot. They're all coming out in blue because of the way I coded it however. If anyone knows how I can change their colors automatically instead of changing my code and going through one by one, that would be awesome.
clear all; close all; clc;
%Defining known values
T3=1100;
nT=0.89;
nC=0.84;
T1=290;
P1=101.325;
k=1.4;
% Overall Efficiency: nth=1-(T1/T3)*((rp)^((k-1)/k))
%%Varying Only Pressure Ratio
rp(1)=0;
i=1;
while rp<=30
nth(i)=1-(T1/T3)*((rp(i)^((k-1)/k)));
i=i+1;
rp(i)=rp(i-1)+0.1;
end
nth(i)=1-(T1/T3)*((rp(i)^((k-1)/k)));
plot(rp,nth);
%%Varying Pressure Ratio and Turbine Inlet Temperature
figure;
T3=800;
while T3<=1500
rp=0;
nth=0;
i=1;
while rp<=30
nth(i)=1-(T1/T3)*((rp(i)^((k-1)/k)));
i=i+1;
rp(i)=rp(i-1)+0.1;
end
nth(i)=1-(T1/T3)*((rp(i)^((k-1)/k)));
plot(rp,nth);
hold on;
T3=T3+100;
end
grid on;
title('Varying Turbine Inlet Temperature');
xlabel('Pressure Ratio, r_p');
ylabel('Thermal Efficiency, \eta_t_h');
legend('800K','900K','1000K','1100K','1200K','1300K','1400K','1500K');
The "Varying Turbine Inlet Temperature" is the plot I am interested in.

採用された回答

Jiro Doke
Jiro Doke 2011 年 2 月 2 日
Here are a few pointers:
  1. To use the auto coloring with plot, use hold all instead of hold on.
  2. The default ColorOrder has only 7 colors. This means that after 7 lines, the color repeats. To have more colors, change the ColorOrder of the axes to have more color (in the form of m-by-3 matrix of RGB values).
  3. There are some preset colormaps that you can use. For example, you can create 8 colors that span the JET colormap by using the command jet(8).
The key lies in the two lines after the figure command below.
clear all; close all; clc;
%Defining known values
T1=290;
T3=800;
k=1.4;
%%Varying Pressure Ratio and Turbine Inlet Temperature
figure;
set(gca, 'ColorOrder', jet(8));
hold all
while T3<=1500
rp=0;
nth=0;
i=1;
while rp<=30
nth(i)=1-(T1/T3)*((rp(i)^((k-1)/k)));
i=i+1;
rp(i)=rp(i-1)+0.1;
end
nth(i)=1-(T1/T3)*((rp(i)^((k-1)/k)));
plot(rp,nth);
T3=T3+100;
end
grid on;
title('Varying Turbine Inlet Temperature');
xlabel('Pressure Ratio, r_p');
ylabel('Thermal Efficiency, \eta_t_h');
legend('800K','900K','1000K','1100K','1200K','1300K','1400K','1500K');
  1 件のコメント
Jeremy
Jeremy 2011 年 2 月 2 日
Thanks, worked like a charm. I couldn't get it to work at first and I realized I forgot to take the hold on out.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by