Fading colors in contourf

7 views (last 30 days)
Xander Caerts
Xander Caerts on 4 Dec 2021
Commented: DGM on 5 Dec 2021
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]')

Accepted Answer

Chunru
Chunru on 4 Dec 2021
%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 Comments
Xander Caerts
Xander Caerts on 4 Dec 2021
Without the lines ('Linecolor', 'none' ), that gives me exactly what I was looking for. Thank you!
DGM
DGM on 5 Dec 2021
If you're after interpolated color with no lines, then you really don't need a contour plot at all. Just use pcolor().

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!