Unwanted contour lines generated by contour()
6 次查看(过去 30 天)
显示 更早的评论
Hi,
I can't seem to figure out why contour() is plotting the additional contours on the outer edge of the shape produced by pcolor().
The following function was used to calculate the values for the matrix M used to create the pcolor plot;
function val = TBM(theta,beta,M_upstream,g)
% Description: TBM function solves Theta-Beta-Mach Relation for required values
% Specifying option to turn off fsolve dialogue in the command window
option = optimset('Display','off');
% Solving for theta
% Identifying required variable
if theta == 0
% Creating function handle of TBM equation in terms of required
% variable
TBM_eq = @(theta) 2*cotd(beta)*((M_upstream^2*(sind(beta))^2-1)/(M_upstream^2*(g+cosd(2*beta))+2)) - tand(theta);
% Solving equation for required variable
val = fsolve(TBM_eq,0.1,option);
% Solving for beta
elseif beta == 0
TBM_eq = @(beta) 2*cotd(beta)*((M_upstream^2*(sind(beta))^2-1)/(M_upstream^2*(g+cosd(2*beta))+2)) - tand(theta);
val = fsolve(TBM_eq,0.1,option);
% Solving for upstream Mach number
elseif M_upstream == 0
TBM_eq = @(M_upstream) 2*cotd(beta)*((M_upstream^2*(sind(beta))^2-1)/(M_upstream^2*(g+cosd(2*beta))+2)) - tand(theta);
val = fsolve(TBM_eq,0.1,option);
end
end
The following code produces the plot;
clear all; close all; clc
% Values
g = 1.4; % Ratio of specific heats for given gas
% Define the range of theta and beta values
theta = 0.5:0.5:50; % Range of theta from 0 to 50 degrees
beta = linspace(90,0.5,length(theta)); % Range of beta from 0 to 90 degrees
% Calculate Mach numbers for every theta beta combination
Mach = zeros(length(theta),length(beta));
for i = 1:1:length(theta)
for j = 1:1:length(beta)
M = TBM(theta(i),beta(j),0,g); % Mach number calculated using a function
if M <= 10
Mach(j,i) = M;
end
end
end
%%
% Create the heatmap for specified Mach numbers
figure("Name","Theta-Beta-Mach Relation Plot");
h = pcolor(theta,beta,Mach); % Pseudocolor plot used instead of heatmap
colormap turbo
c = colorbar;
c.Label.String = "M";
h.EdgeColor = "None";
hold on
% Add contours to heatmap
M_cont = [1.1:0.1:2 2.1:0.2:4 4.25:0.25:5 6 7 8 10];
[c,h] = contour(theta,beta,Mach,M_cont,"EdgeColor","w");
clabel(c,h,"FontSize",8,"Color","w")
xlabel("Theta (degrees)");
ylabel("Beta (degrees)");
title("Theta-Beta-Mach Relation");
As shown above, the additional contours produce the thick white outline.
Any help is greatly appreciated. Thanks!
0 个评论
回答(1 个)
Chunru
2023-10-17
编辑:Chunru
2023-10-17
Yo5ur function curve has very abrupt change near the ege (see one vertical slice of data). Therefore you will see many contour lines near the edge (to the dark color). Check out if the generated data is what you expect.
clear all; close all; clc
% Values
g = 1.4; % Ratio of specific heats for given gas
% Define the range of theta and beta values
theta = 0.5:0.5:50; % Range of theta from 0 to 50 degrees
beta = linspace(90,0.5,length(theta)); % Range of beta from 0 to 90 degrees
% Calculate Mach numbers for every theta beta combination
% Mach = zeros(length(theta),length(beta));
Mach = nan(length(theta),length(beta));
for i = 1:1:length(theta)
for j = 1:1:length(beta)
M = TBM(theta(i),beta(j),0,g); % Mach number calculated using a function
if M <= 10
Mach(j,i) = M;
end
end
end
%%
% Create the heatmap for specified Mach numbers
figure("Name","Theta-Beta-Mach Relation Plot");
h = pcolor(theta,beta,Mach); % Pseudocolor plot used instead of heatmap
colormap turbo
c = colorbar;
c.Label.String = "M";
h.EdgeColor = "None";
hold on
% Add contours to heatmap
M_cont = [1.1:0.1:2 2.1:0.2:4 4.25:0.25:5 6 7 8 10];
%M_cont = [1.1:0.1:2 2.1:0.3:2.7 ];
% M_cont = [2.7 2.7]
[c,h] = contour(theta,beta,Mach,M_cont,"EdgeColor","w");
clabel(c,h,"FontSize",8,"Color","w")
xlabel("Theta (degrees)");
ylabel("Beta (degrees)");
title("Theta-Beta-Mach Relation");
whos
figure
plot(Mach(:, 50)) % a verticle slice of data
function val = TBM(theta,beta,M_upstream,g)
% Description: TBM function solves Theta-Beta-Mach Relation for required values
% Specifying option to turn off fsolve dialogue in the command window
option = optimset('Display','off');
% Solving for theta
% Identifying required variable
if theta == 0
% Creating function handle of TBM equation in terms of required
% variable
TBM_eq = @(theta) 2*cotd(beta)*((M_upstream^2*(sind(beta))^2-1)/(M_upstream^2*(g+cosd(2*beta))+2)) - tand(theta);
% Solving equation for required variable
val = fsolve(TBM_eq,0.1,option);
% Solving for beta
elseif beta == 0
TBM_eq = @(beta) 2*cotd(beta)*((M_upstream^2*(sind(beta))^2-1)/(M_upstream^2*(g+cosd(2*beta))+2)) - tand(theta);
val = fsolve(TBM_eq,0.1,option);
% Solving for upstream Mach number
elseif M_upstream == 0
TBM_eq = @(M_upstream) 2*cotd(beta)*((M_upstream^2*(sind(beta))^2-1)/(M_upstream^2*(g+cosd(2*beta))+2)) - tand(theta);
val = fsolve(TBM_eq,0.1,option);
end
end
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!