Fading colors in contourf

조회 수: 7 (최근 30일)
Xander Caerts
Xander Caerts 2021년 12월 4일
댓글: DGM 2021년 12월 5일
I have some data to process and to do so, I'm using a contourf-function. I would like my plots to have the colors fading into eachother instead of having clear lines between zones. Anyone that can help me with this?
%Processing input
Data = importdata('NH3.txt').data;
Speed = importdata('Speed.txt').data;
[Y,Z] = meshgrid(unique(Data(:,2),'sorted'),flip(unique(Data(:,3),'sorted')));
NH3 = zeros(65); %pre-allocation
U = zeros(65); %pre-allocation
for r = 1:65
for k = 1:65
NH3(r,k) = Data(find(Data(:,2)== Y(k,k) & Data(:,3) == Z(r,r)), 4);
U(r,k) = Speed(find(Speed(:,2)== Y(k,k) & Speed(:,3) == Z(r,r)), 4);
end
end
%Plotting
subplot(1,2,1)
contourf(Y, Z, NH3, 'Linecolor', 'none')
colorbar
title('NH_3 concentratie [kg/m³]')
xlabel('y [m]')
ylabel('z [m]')
subplot(1,2,2)
contourf(Y, Z, U, 'Linecolor', 'none')
colorbar
title('Snelheid in x-component [m/s]')
xlabel('y [m]')
ylabel('z [m]')

채택된 답변

Chunru
Chunru 2021년 12월 4일
%Processing input
Data = importdata('NH3.txt').data;
Speed = importdata('Speed.txt').data;
yy = unique(Data(:,2),'sorted');
zz = flip(unique(Data(:,3),'sorted'));
[Y,Z] = meshgrid(unique(Data(:,2),'sorted'),flip(unique(Data(:,3),'sorted')));
NH3 = zeros(65); %pre-allocation
U = zeros(65); %pre-allocation
for r = 1:65
for k = 1:65
NH3(r,k) = Data(find(Data(:,2)== Y(k,k) & Data(:,3) == Z(r,r)), 4);
U(r,k) = Speed(find(Speed(:,2)== Y(k,k) & Speed(:,3) == Z(r,r)), 4);
end
end
%Plotting
subplot(1,2,1)
imagesc(yy, zz, NH3); hold on
contour(Y, Z, NH3, 'Linecolor', 'k')
colorbar
title('NH_3 concentratie [kg/m³]')
xlabel('y [m]')
ylabel('z [m]')
subplot(1,2,2)
imagesc(yy, zz, U); hold on
contour(Y, Z, U, 'Linecolor', 'k')
colorbar
title('Snelheid in x-component [m/s]')
xlabel('y [m]')
ylabel('z [m]')
  댓글 수: 2
Xander Caerts
Xander Caerts 2021년 12월 4일
Without the lines ('Linecolor', 'none' ), that gives me exactly what I was looking for. Thank you!
DGM
DGM 2021년 12월 5일
If you're after interpolated color with no lines, then you really don't need a contour plot at all. Just use pcolor().

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by