Plotting contourf with discrete x axis
조회 수: 13 (최근 30일)
이전 댓글 표시
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
채택된 답변
Kelly Kearney
2020년 2월 28일
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]);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!