Plot not showing the desired markers and does not match the legend
Show older comments
Hello everyone,
I am trying to plot theta vs Cp. Cp here is calculated based on the function provided. However when plotted, the markers are not showing properly and does not match the legend.
Any help is appreciated!
I have attached the plot as well as the function and the main file.
Function File:
function Cp = Experiment_1(H,Ch11)
cu = 9.8; %mm of H20 to Pascal
%H=[-0.3,-0.5,-2.1,-3.3,-3.5,-3.2,-3.1,-3.1,-3.2,-2.7];
Ch11 = Ch11.*cu; % Converting channel 11 pressure to Pascal
for i=1:length(H)
H(i) = H(i).*cu; % To convert to Pascal
end
% Convert pressure readings to total pressure
P_atm = 99991.7925; % Pascal
for i=1:length(H)
Pt(i) = P_atm + H(i);
end
Ch11 = P_atm + Ch11;
% theta
theta = linspace(0,180,10);
% Generate the plot for total pressure
%{
plot(theta,Pt, 'o', 'MarkerSize', 5, 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'g');
xlabel("$\theta[degrees]$","Interpreter","latex","FontSize",12)
ylabel("$Total Pressure, P_{o}[atm]$","Interpreter","latex","FontSize",12)
grid on
axis equal
set(gca,'TickLabelInterpreter','latex','layer','top');
set(gca,'TickDir','out')
set(gca, 'Layer', 'bottom')
%}
% Calculation of Cp experimental
Cp = (Pt- Ch11)./((1.0/2.0)*1.225*6.4*6.4);
% Plot the Cp along the circular cylinder
plot(theta, Cp, '-d', 'MarkerSize',5,'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'g');
hold on
plot(theta, Cp, '-o', 'MarkerSize',5)
hold on
plot(theta, Cp, '-+', 'MarkerSize',5)
hold on
plot(theta, Cp, '-*', 'MarkerSize',5)
hold on
plot(theta, Cp, '-x', 'MarkerSize',5)
xlabel('$\theta\ [^\circ]$',"Interpreter","latex","FontSize",12)
ylabel('$C_p$',"Interpreter","latex","FontSize",12)
grid on
set(gca,'TickLabelInterpreter','latex','layer','top');
set(gca,'TickDir','out')
set(gca, 'Layer', 'bottom')
legend("V=6.4 m/s", "V = 8.7 m/s" , "V = 11 m/s" , "V = 14.3 m/s", "V=12.1 m/s","Interpreter","latex")
%%
sfname = "C:\IITM MATLAB\LAB AS5110\Images\";
export_fig(strcat(sfname,'Cp20Fan'),'-png','-transparent','-m4');
Main File:
figure;
hold on;
H20 = [-0.3,-0.5,-2.1,-3.3,-3.5,-3.2,-3.1,-3.1,-3.2,-2.7];
Ch11_1 = -2.1;
H30 = [-0.3,-1.2,-4.5,-7.4,-7.5,-7.1,-6.9,-7.0,-7.0,-6.5];
Ch11_2 = -4.1;
H40 = [-0.3,-2.2,-7.5,-12.5,-12.4,-11.9,-11.8,-12.3,-12.1,-11.4];
Ch11_3 = -7.0;
H45 = [-0.5,-2.7,-9.4,-15.6,-15.6,-14.8,-14.8,-15.1,-15.0,-14.4];
Ch11_4 = -8.7;
H55 = [-0.5,-3.9,-13.4,-22.4,-22.0,-21.1,-21.0,-21.8,-21.6,-20.9];
Ch11_5 = -12.2;
Cp20 = Experiment_1(H20, Ch11_1);
Cp30 = Experiment_1(H30, Ch11_2);
Cp40 = Experiment_1(H40, Ch11_3);
Cp45 = Experiment_1(H45, Ch11_4);
Cp55 = Experiment_1(H55, Ch11_5);
2 Comments
Thanks for putting code in line; much simpler than if have to download and then repost...
function Cp = Experiment_1(H,Ch11)
cu = 9.8; %mm of H20 to Pascal
%H=[-0.3,-0.5,-2.1,-3.3,-3.5,-3.2,-3.1,-3.1,-3.2,-2.7];
Ch11 = Ch11.*cu; % Converting channel 11 pressure to Pascal
H= H*cu; % To convert to Pascal - use MATLAB array operations instead of loop...
% Convert pressure readings to total pressure
P_atm = 99991.7925; % Pascal
Pt=P_atm + H;
Ch11 = P_atm + Ch11;
% theta
theta = linspace(0,180,10);
% Calculation of Cp experimental
Cp = (Pt- Ch11)./((1.0/2.0)*1.225*6.4*6.4);
% Plot the Cp along the circular cylinder
plot(theta, Cp, '-d', 'MarkerSize',5,'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'g');
hold on
plot(theta, Cp, '-o', 'MarkerSize',5)
plot(theta, Cp, '-+', 'MarkerSize',5)
plot(theta, Cp, '-*', 'MarkerSize',5)
plot(theta, Cp, '-x', 'MarkerSize',5)
...
Above uses MATLAB vectorized operations for the units conversions; no loops needed for arithmetic operations on arrays. That's the key feature of MAT[rix]LAB[oratory].
Also for efficiency/brevity, remove the superfluous "hold on" calls; once "on" is set, it can't get any more "on-er". <g>
Towards the specific question asked about, the above plot commands all plot the identical data so all that will show in the end will be the last line with the '-x' marker/linestyle. The colors will cycle through the default color map.
When you then call the function five separate time with the five repetitions of the plot inside, then you end up with the markers all being on top of each other in a blob in the plot, but the legend still is for each of the five individual line styles.
Accepted Answer
More Answers (1)
Star Strider
on 8 Aug 2025
Edited: Star Strider
on 9 Aug 2025
It is difficult for me to understand what you're doing, although I believe this is close to what you want --
% ----- Experiment_1 -----
function Cp = Experiment_1(H,Ch11,ls)
Ch11_label = -Ch11;
cu = 9.8; %mm of H20 to Pascal
%H=[-0.3,-0.5,-2.1,-3.3,-3.5,-3.2,-3.1,-3.1,-3.2,-2.7];
Ch11 = Ch11.*cu; % Converting channel 11 pressure to Pascal
for i=1:length(H)
H(i) = H(i).*cu; % To convert to Pascal
end
% Convert pressure readings to total pressure
P_atm = 99991.7925; % Pascal
for i=1:length(H)
Pt(i) = P_atm + H(i);
end
Ch11 = P_atm + Ch11;
% theta
theta = linspace(0,180,10);
% Generate the plot for total pressure
%{
plot(theta,Pt, 'o', 'MarkerSize', 5, 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'g');
xlabel("$\theta[degrees]$","Interpreter","latex","FontSize",12)
ylabel("$Total Pressure, P_{o}[atm]$","Interpreter","latex","FontSize",12)
grid on
axis equal
set(gca,'TickLabelInterpreter','latex','layer','top');
set(gca,'TickDir','out')
set(gca, 'Layer', 'bottom')
%}
% Calculation of Cp experimental
Cp = (Pt- Ch11)./((1.0/2.0)*1.225*6.4*6.4);
% Plot the Cp along the circular cylinder
if Ch11_label == 2.1
plot(theta, Cp, ls, 'MarkerSize',5,'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'g','DisplayName',sprintf('V = %5.1f m/s',Ch11_label));
% hold on
else
plot(theta, Cp, ls, 'MarkerSize',5,'DisplayName',sprintf('V = %5.1f m/s',Ch11_label))
end
% plot(theta, Cp, '-o', 'MarkerSize',5)
% hold on
% plot(theta, Cp, '-+', 'MarkerSize',5)
% hold on
% plot(theta, Cp, '-*', 'MarkerSize',5)
% hold on
% plot(theta, Cp, '-x', 'MarkerSize',5)
xlabel('$\theta\ [^\circ]$',"Interpreter","latex","FontSize",12)
ylabel('$C_p$',"Interpreter","latex","FontSize",12)
grid on
set(gca,'TickLabelInterpreter','latex','layer','top');
set(gca,'TickDir','out')
set(gca, 'Layer', 'bottom')
legend(Location='best', Interpreter='LaTeX')
% legend("V=6.4 m/s", "V = 8.7 m/s" , "V = 11 m/s" , "V = 14.3 m/s", "V=12.1 m/s","Interpreter","latex")
%%
sfname = "C:\IITM MATLAB\LAB AS5110\Images\";
% % % % % export_fig(strcat(sfname,'Cp20Fan'),'-png','-transparent','-m4');
end
%{
p-p(inf)= Rho g [C1 - C11]
cp = p-p(inf) / 0.5 rho(air) v^2
%}
%%
%{
C11 = -2.1;
H = [-0.3,-0.5,-2.1,-3.3,-3.5,-3.2,-3.1,-3.1,-3.2,-2.7];
for i = 1:length(H)
subt(i) = (1000*9.81 * (H(i) - C11))./1000;
cp(i) = subt(i)./(0.5*1.225 * 6.4*6.4);
end
plot(theta,cp)
%}
% ----- Experiment_1_Main -----
figure;
hold on;
H20 = [-0.3,-0.5,-2.1,-3.3,-3.5,-3.2,-3.1,-3.1,-3.2,-2.7];
Ch11_1 = -2.1;
H30 = [-0.3,-1.2,-4.5,-7.4,-7.5,-7.1,-6.9,-7.0,-7.0,-6.5];
Ch11_2 = -4.1;
H40 = [-0.3,-2.2,-7.5,-12.5,-12.4,-11.9,-11.8,-12.3,-12.1,-11.4];
Ch11_3 = -7.0;
H45 = [-0.5,-2.7,-9.4,-15.6,-15.6,-14.8,-14.8,-15.1,-15.0,-14.4];
Ch11_4 = -8.7;
H55 = [-0.5,-3.9,-13.4,-22.4,-22.0,-21.1,-21.0,-21.8,-21.6,-20.9];
Ch11_5 = -12.2;
Cp20 = Experiment_1(H20, Ch11_1, '-d');
Cp30 = Experiment_1(H30, Ch11_2,'-o');
Cp40 = Experiment_1(H40, Ch11_3, '-+');
Cp45 = Experiment_1(H45, Ch11_4, '-*');
Cp55 = Experiment_1(H55, Ch11_5, '-x');
% ---------------------- END ----------------------
I have my own script that retrieves the text from posted .m files that I used for this.
One problem is that you were printing all the data in each call to the function that actually should only print one plot at a time. I changed that. I added DisplayName calls to tine individual plot calls.
Make appropriate changes to get the result you want.
EDIT -- (9 Aug 2025 at 01:11)
I just realised that you want the specific plot details ('MarkerFaceColor', and so on) only with the first data plot ('Ch11_1 = -2.1') and apparently want the other colours to 'float', using the usual MATLAB ColorOrder. I added an if block to create that effect.
.
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





