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 Center および File ExchangeSimulink Functions についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by