필터 지우기
필터 지우기

Unwanted contour lines generated by contour()

조회 수: 3 (최근 30일)
Dominic Babula
Dominic Babula 2023년 10월 17일
편집: Chunru 2023년 10월 17일
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!
Chunru
Chunru 2023년 10월 17일
Use nan instead of 0 as updated above

댓글을 달려면 로그인하십시오.

카테고리

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