xlim and ylim for contourf

조회 수: 47 (최근 30일)
Alli Whalley
Alli Whalley 2020년 9월 28일
댓글: Alli Whalley 2020년 10월 3일
I need to add limits for the extent of where data was collected on a model. ie. the model goes from 0-900 but we only took measurements from 40-870 or something. I want the plot to show the full model dimensions.
I'm using contour plots. I have tried using xlim and ylim but it will only work for one or the other, depending where they appear in the code. I can't get it to use both.
subplot(1,4,1);
pressure_values = data_means(faces.front.tap_number);
faces.front.pressure = pressure_values;
x_size = length(unique(faces.front.x));
y_size = length(unique(faces.front.y));
z_size = length(unique(faces.front.z));
x_mesh = squeeze(reshape(faces.front.x,x_size,y_size,z_size));
y_mesh = squeeze(reshape(faces.front.y,x_size,y_size,z_size));
z_mesh = squeeze(reshape(faces.front.z,x_size,y_size,z_size));
pressure_mesh = squeeze(reshape(faces.front.pressure,x_size,y_size,z_size));
contourf(x_mesh, z_mesh, pressure_mesh,25,':');
colormap(gca,'jet')
hcb1 = colorbar;
title('FRONT');
ylim([0,900]);
xlim([-112.5,112.5]);
caxis(clims);
axis equal
Thanks!

채택된 답변

Raunak Gupta
Raunak Gupta 2020년 10월 2일
Hi,
The axis equal command after xlim and ylim squeezes one of the axis limits to fit the figure box into minimum space. This happens due to PlotBoxAspectRatioMode being set to auto by default and it has stretch to fill inbuilt property. To get out of this expected behavior you can replace the order of axis and xlim/ylim commands. Last four lines of your code can be replaced as follows:
axis equal
ylim([0,900]);
xlim([-112.5,112.5]);
caxis(clims);
  댓글 수: 1
Alli Whalley
Alli Whalley 2020년 10월 3일
That's great, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by