xlim and ylim for contourf

46 views (last 30 days)
Alli Whalley
Alli Whalley on 28 Sep 2020
Commented: Alli Whalley on 3 Oct 2020
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!

Accepted Answer

Raunak Gupta
Raunak Gupta on 2 Oct 2020
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);

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!