Fading colors in contourf

7 visualizzazioni (ultimi 30 giorni)
Xander Caerts
Xander Caerts il 4 Dic 2021
Commentato: DGM il 5 Dic 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]')

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulink Functions in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by