How to make contour to have the same axes

I have a two different plots with 2 different axes. The second plot (fig2) is extracted from the first plot (fig1).
Please how can I make the extract plot to have the same axis as the first one. I tried aspect ratio function but couldn't work.
openfig('fig1.fig');
openfig('fig2.fig');

11 Comments

Please share the code you used to create both plots.
Are you saying fig2 should keep the axes as labeled, with the plot filling the figure window, or should the figure essentially be zoomed to the exact borders of the contour plot so that it fills the figure window?
Thank you Cris. Not really zooming it. I think I was able to zoom it with your assitance last week but that wasn't what I wanted. I want the fig2 to plot fill the figure window.
See code:
fig2 = figure(2);
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
c.TickLabelInterpreter='latex';
c.Label.String = '$\int u_L \mathrm{dz} $';
c.Label.Interpreter = 'latex';
colormap jet
clabel(C,h)
hold on
for i=1:length(L)
for j=1:length(xi)
plot(L(i), xi(j), 'w.', 'LineWidth', 2, 'MarkerSize', 5)
end
end
set(gca,'clim',[min(min(intul)) max(max(intul))]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fig2 = figure(2);
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
c.TickLabelInterpreter='latex';
c.Label.String = '$\int u_L \mathrm{dz} $';
c.Label.Interpreter = 'latex';
colormap jet
clabel(C,h)
hold on
for i=1:length(L)
for j=1:length(xi)
plot(L(i), xi(j), 'w.', 'LineWidth', 2, 'MarkerSize', 5)
end
end
set(gca,'clim',[min(min(intul)) max(max(intul))]);
% axis label
xlabel('HAN region length, $l$ [m]','Interpreter','latex');
ylabel('activity, $\xi$','Interpreter','latex');
xlim([pars.W/1000, pars.W/3])
ylim([0, 125])
I set the limit of fig2 using the axix of fig1.
The reason it is not filling the axes is because you have set the limits of fig2 to be the same as fig1. If fig2 is indeed a subset of fig1, then you need to use the limits of the data in fig2 to set the axes limits. Otherwise, you are plotting it the same size it was in the original figure. Where there is no data remains white.
Yeah I understand what you mean. This is the actual figure without setting the limit.
openfig('fig2_actual.fig');
Also, I think you copied the same code twice rather than code that creates the 2 figures you attached.
The figures are coded differently. I added more points around the isolated maxumum to extract more information.
% axis for first figure
xivals = linspace(0, 125, 20);
Lvals = linspace(2e-8, 6.6667e-6, 20);
% axis for second figure
xivals = linspace(47.8947, 123.158, 20);
Lvals = linspace(7.19649e-07, 3.51825e-06, 20);
I have attached data for each of the figures
Can you update your post to use the tools in the ribbon to create formatted code, and then run that code so that it creates each figure here? Smiilar to what I did here.
load data_0_125.mat
figure;
xi = linspace(0, 125,20);
L=linspace(2e-08, 6.66666666666667e-06, 20);
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
c.TickLabelInterpreter='latex';
c.Label.String = '$\int u_L \mathrm{dz} $';
c.Label.Interpreter = 'latex';
colormap jet
clabel(C,h)
hold on
for i=1:length(L)
for j=1:length(xi)
plot(L(i), xi(j), 'w.', 'LineWidth', 2, 'MarkerSize', 5)
end
end
set(gca,'clim',[min(min(intul)) max(max(intul))]);
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\int u_L \mathrm{dz} $
%%%%%
load data_xi_48_123.mat
figure;
xivals = linspace(47.8947, 123.158, 20);
Lvals = linspace(7.19649e-07, 3.51825e-06, 20);
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
c.TickLabelInterpreter='latex';
c.Label.String = '$\int u_L \mathrm{dz} $';
c.Label.Interpreter = 'latex';
colormap jet
clabel(C,h)
set(gca,'clim',[min(min(intul)) max(max(intul))]);
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\int u_L \mathrm{dz} $
Thank you so much Cris and Torsten.

Sign in to comment.

Answers (0)

Products

Release

R2023b

Asked:

on 9 Feb 2024

Commented:

on 9 Feb 2024

Community Treasure Hunt

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

Start Hunting!