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!

回答(1 个)

Chunru
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
Name Size Bytes Class Attributes M 1x1 8 double M_cont 1x28 224 double Mach 100x100 80000 double beta 1x100 800 double c 2x4823 77168 double g 1x1 8 double h 1x1 8 matlab.graphics.chart.primitive.Contour i 1x1 8 double j 1x1 8 double theta 1x100 800 double
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 个评论
Dominic Babula
Dominic Babula 2023-10-17
Thanks for bringing that to my attention. Considering this, the generated data is expected. I essentially terminated the pcolor plot at M-values >= 10 by setting them to zero, which caused these spikes in value. This was done as the display of larger M-values was not required.
I do not want to display these contours, how would you go about this? Is there a simple way to do it?
Thanks!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by