Plotting contourf with discrete x axis

6 Ansichten (letzte 30 Tage)
G E
G E am 28 Feb. 2020
Bearbeitet: G E am 29 Feb. 2020
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 :)

Akzeptierte Antwort

Kelly Kearney
Kelly Kearney am 28 Feb. 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]);
  1 Kommentar
G E
G E am 29 Feb. 2020
Bearbeitet: G E am 29 Feb. 2020
Amazing - thank you very much for the quick reply and detailed explanation!
imagesc exactly what I needed - very happy with it :))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by