Plotting contourf with discrete x axis
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I am struggling to plot some data using contourf, and would be extremely grateful for any advice.
My data ("Temp", 10000x10) contains the temperature in 10 vertical "zones" (zone 10 = bottom, hot part, zone 1 = top, cooler part) of a blast furnace, modelled over 10,000 seconds.
I would like to do a contour plot, showing how the temperature changes in all zones vs. time. Ideally, I would get the zone number on the y axis (discrete), the time on the x axis, and the temperature as the colour.
When I plot:
contourf(Temp,50)
I get the following:
MATLAB seems to be doing some sort of interpolation along each "zone" - how can I remove this? The zone (x axis) should be discrete - there is no zone 5.5, just zone 5 and zone 6.
I also can't get the axes to swap despite my best attempts!
Would be extremely grateful for any advice :)
0 commentaires
Réponse acceptée
Kelly Kearney
le 28 Fév 2020
The contour function always assumes your input data are points on a surface that can be linearly interpolated between. To get a plot with discrete blocks, you have a few options.
1) Plot using imagesc or pcolor
2) Upsample the data before plotting.
Also, to swap axes, you need to provide x and y inputs or transpose your matrix.
% Data
x1 = 1:10;
y1 = 1:20;
[x3,y3] = meshgrid(x1,y1);
Temp = peaks(20); % Some sample data
Temp = Temp(:,1:10);
% Upsampled data
x2 = linspace(0,10.5,100);
Temp2 = interp1(1:10,Temp',x2,'nearest')';
% Plot options
ax(1) = subplot(2,2,1);
imagesc(x1,y1,Temp);
title('imagesc(Temp)');
hold on;
scatter(x3(:), y3(:), [], Temp(:), 'filled', 'markeredgecolor', 'k');
set(gca, 'ydir', 'normal');
ax(2) = subplot(2,2,2);
pcolor(x1,y1,Temp);
shading flat;
title('pcolor(Temp)');
hold on;
scatter(x3(:), y3(:), [], Temp(:), 'filled', 'markeredgecolor', 'k');
set(gca, 'ydir', 'normal');
ax(3) = subplot(2,2,3);
contourf(x1,y1,Temp,50);
title('contourf(Temp)');
hold on;
scatter(x3(:), y3(:), [], Temp(:), 'filled', 'markeredgecolor', 'k');
ax(4) = subplot(2,2,4);
contourf(x2, y1, Temp2,50);
title('contourf(Temp2)');
hold on;
scatter(x3(:), y3(:), [], Temp(:), 'filled', 'markeredgecolor', 'k');
set(ax, 'clim', [-5 7], 'xlim', [0.5 10.5], 'ylim', [0.5 20.5]);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Contour Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!