Keeping the scale in subplots when one is changed
Show older comments
Hi, I have the following plot. When I used the option "axis square" for Figure (b), Figure (c) does not scale properly with figure (b) in the x axis. Is there away how to keep the scale similar in the other figures despite I changed the properties of one of them. I have attached the file that contains the data. Thank you for your help.

load South_America_database.mat
% creating the matrices to save the unique values of latitude and longitude for the stations for the entire database as their values differ from one another
South_America_database.LATS=zeros(length(South_America_database.unique_stations),1);
South_America_database.LONS=zeros(length(South_America_database.unique_stations),1);
for i=1:length(South_America_database.unique_stations)
ind_station=find(strcmp(South_America_database.unique_stations(i),deblank(South_America_database.station)));
South_America_database.LATS(i)=South_America_database.LATStations(ind_station(1));
South_America_database.LONS(i)=South_America_database.LONStations(ind_station(1));
end
% Extracting the list of unique stations for interface earthquakes
stations_interface=South_America_database.station(South_America_database.ETC==0);
stations_interface=unique(stations_interface);
lat_interface_station=zeros(length(stations_interface),1);
lon_interface_station=zeros(length(stations_interface),1);
% extracting the coordinates of the unique stations for interface
for i=1:length(stations_interface)
ind_find=find(strcmp(stations_interface(i),South_America_database.unique_stations));
lat_interface_station(i)=South_America_database.LATS(ind_find);
lon_interface_station(i)=South_America_database.LONS(ind_find);
end
% Eliminating diplicate values from the stations
matrix_interface=[lat_interface_station lon_interface_station];
matrix_interface=unique(matrix_interface,'rows');
% replacing the final values of the stations
lat_interface_station=matrix_interface(:,1);
lon_interface_station=matrix_interface(:,2);
%% PLOT FOR INTERFACE EARTHQUAKES
EQ=0;
fsz = 25;
color_text=[0.09 0.27 0.68];
figure
subplot(4,4,[2,3,4,6,7,8,10,11,12])
% Assuming you have your data in variables: event_lon, event_lat, station_lon, station_lat
% Load coastline data
load coastlines
plot(coastlon, coastlat, 'k-', 'DisplayName', 'Coastlines');hold on
plot(lon_interface_station,lat_interface_station, '^','MarkerSize',5,'MarkerEdgeColor',[0.38 0.22 0.22],'MarkerFaceColor',[0.93 0.30 0.30],'LineWidth',1.5, 'DisplayName', 'Station'); hold on
plot(South_America_database.LONE(South_America_database.ETC==EQ), South_America_database.LATE(South_America_database.ETC==EQ), 'o','MarkerSize',5,'MarkerEdgeColor',[0.29 0.50 0.6],'MarkerFaceColor',[0.30 0.62 0.78],'LineWidth',1.5, 'DisplayName', 'Interface Earthquakes');hold on
%plot(South_America_database.LONE(South_America_database.ETC==1), South_America_database.LATE(South_America_database.ETC==1), 'o','MarkerSize',10,'MarkerEdgeColor',[0.57 0.50 0.20],'MarkerFaceColor',[0.93 0.77 0.13],'LineWidth',1.5, 'DisplayName', 'Intraslab Earthquakes');hold on
set(gca, 'FontName', 'Times New Roman', 'FontSize', fsz-3, 'FontWeight', 'bold', ...
'XColor', color_text, 'YColor', color_text, 'XTickLabelRotation', 0, ...
'LineWidth', 0.5, 'GridColor', [0.5, 0.5, 0.5], 'GridAlpha', 0.5,'XTickLabel', [], 'XGrid','on', 'YGrid','on');
%xlabel('Longitude (°)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
%ylabel('Latitude (°)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
xlim([-85 -60])
ylim([-60 10])
grid on
%axis equal
axis square
legend('Location','northeast','color',[0.97 0.96 0.96],'TextColor', [0 0.35 0.74],'EdgeColor',[0 0.35 0.74],'FontSize',10,'LineWidth',1);
titl = strcat('(b)');
title(titl,'FontSize',fsz+2,'color',color_text,'FontWeight', 'bold');
% Adjust overall figure appearance
set(gcf, 'Color', 'w')
a11=[0.56 0.23 0.54];
a12=[0.97 0.38 0.93];
a21=[0.29 0.60 0.37];
a22=[0.11 0.94 0.33];
a31=[0.14 0.25 0.46];
a32=[0.10 0.38 0.93];
a41=[0.62 0.17 0.17];
a42=[0.91 0.1 0.1];
subplot(4,4,[1,5,9])
plot([South_America_database.Ztor(South_America_database.ETC==EQ & South_America_database.Mw>=5 & South_America_database.Mw<6)],[South_America_database.LATE(South_America_database.ETC==EQ & South_America_database.Mw>=5 & South_America_database.Mw<6)],'o' ,'MarkerSize',5,'MarkerEdgeColor',a11,'MarkerFaceColor',a12,'LineWidth',1.5, 'DisplayName', 'Mw>=5 & Mw<6'); hold on;
plot([South_America_database.Ztor(South_America_database.ETC==EQ & South_America_database.Mw>=6 & South_America_database.Mw<7)],[South_America_database.LATE(South_America_database.ETC==EQ & South_America_database.Mw>=6 & South_America_database.Mw<7)],'o' ,'MarkerSize',5,'MarkerEdgeColor',a21 ,'MarkerFaceColor',a22,'LineWidth',1.5, 'DisplayName', 'Mw>=6 & Mw<7'); hold on;
plot([South_America_database.Ztor(South_America_database.ETC==EQ & South_America_database.Mw>=7 & South_America_database.Mw<8)],[South_America_database.LATE(South_America_database.ETC==EQ & South_America_database.Mw>=7 & South_America_database.Mw<8)],'o' ,'MarkerSize',5,'MarkerEdgeColor',a31,'MarkerFaceColor',a32,'LineWidth',1.5, 'DisplayName', 'Mw>=7 & Mw<8'); hold on;
plot([South_America_database.Ztor(South_America_database.ETC==EQ & South_America_database.Mw>=8 & South_America_database.Mw<9)],[South_America_database.LATE(South_America_database.ETC==EQ & South_America_database.Mw>=8 & South_America_database.Mw<9)],'o' ,'MarkerSize',5,'MarkerEdgeColor',a41,'MarkerFaceColor',a42,'LineWidth',1.5, 'DisplayName', 'Mw>=8 & Mw<9'); hold on;
xlim([0 75])
ylim([-60 10])
xticks([0, 25 50, 75]); % Set specific tick locations
xticklabels({'0', '25', '50' '75'}); % Set corresponding labels
%axis equal
xlabel('Z_{TOR} (km)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
ylabel('Latitude (°)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
legend('Location','southeast','color',[0.97 0.96 0.96],'TextColor', [0 0.35 0.74],'EdgeColor',[0 0.35 0.74],'FontSize',10,'LineWidth',1);
grid on
set(gca, 'FontName', 'Times New Roman', 'FontSize', fsz-3, 'FontWeight', 'bold', ...
'XColor', color_text, 'YColor', color_text, 'XTickLabelRotation', 0, ...
'LineWidth', 0.5, 'GridColor', [0.5, 0.5, 0.5], 'GridAlpha', 0.5);
% Adjust overall figure appearance
set(gcf, 'Color', 'w')
titl = strcat('(a)');
title(titl,'FontSize',fsz+2,'color',color_text,'FontWeight', 'bold');
subplot(4,4,[14,15,16])
plot([South_America_database.LONE(South_America_database.ETC==EQ & South_America_database.Mw>=5 & South_America_database.Mw<6)],[South_America_database.Ztor(South_America_database.ETC==EQ & South_America_database.Mw>=5 & South_America_database.Mw<6)],'o','MarkerSize',5,'MarkerEdgeColor',a11,'MarkerFaceColor',a12,'LineWidth',1.5, 'DisplayName', 'Mw>=5 & Mw<6'); hold on;
plot([South_America_database.LONE(South_America_database.ETC==EQ & South_America_database.Mw>=6 & South_America_database.Mw<7)],[South_America_database.Ztor(South_America_database.ETC==EQ & South_America_database.Mw>=6 & South_America_database.Mw<7)],'o' ,'MarkerSize',5,'MarkerEdgeColor',a21 ,'MarkerFaceColor',a22,'LineWidth',1.5, 'DisplayName', 'Mw>=6 & Mw<7'); hold on;
plot([South_America_database.LONE(South_America_database.ETC==EQ & South_America_database.Mw>=7 & South_America_database.Mw<8)],[South_America_database.Ztor(South_America_database.ETC==EQ & South_America_database.Mw>=7 & South_America_database.Mw<8)],'o' ,'MarkerSize',5,'MarkerEdgeColor',a31,'MarkerFaceColor',a32,'LineWidth',1.5, 'DisplayName', 'Mw>=7 & Mw<8'); hold on;
plot([South_America_database.LONE(South_America_database.ETC==EQ & South_America_database.Mw>=8 & South_America_database.Mw<9)],[South_America_database.Ztor(South_America_database.ETC==EQ & South_America_database.Mw>=8 & South_America_database.Mw<9)],'o' ,'MarkerSize',5,'MarkerEdgeColor',a41,'MarkerFaceColor',a42,'LineWidth',1.5, 'DisplayName', 'Mw>=8 & Mw<9'); hold on;
xlabel('Latitude (°)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
ylabel('Z_{TOR} (km)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
titl = strcat('(c)');
title(titl,'FontSize',fsz+2,'color',color_text,'FontWeight', 'bold');
xlim([-85 -60])
ylim([0 75])
grid on
legend('Location','northeast','color',[0.97 0.96 0.96],'TextColor', [0 0.35 0.74],'EdgeColor',[0 0.35 0.74],'FontSize',10,'LineWidth',1);
yticks([0, 25 50, 75]); % Set specific tick locations
yticklabels({'0', '25', '50' '75'}); % Set corresponding labels
set(gca, 'FontName', 'Times New Roman', 'FontSize', fsz-3, 'FontWeight', 'bold', ...
'XColor', color_text, 'YColor', color_text, 'XTickLabelRotation', 0, ...
'LineWidth', 0.5, 'GridColor', [0.5, 0.5, 0.5], 'GridAlpha', 0.5);
%axis square reverse
set(gca, 'YDir', 'reverse');
% Adjust overall figure appearance
set(gcf, 'Color', 'w')
8 Comments
Cris LaPierre
on 8 Jan 2025
Jorge Luis
on 8 Jan 2025
Cris LaPierre
on 8 Jan 2025
Please share your code and your data or variables. You can save your variables to a mat file and attach that to your post using the paperclip icon.
dpb
on 8 Jan 2025
Show us exactly...
Adam
on 8 Jan 2025
doc linkprop
can be very useful for keeping properties of two plots the same, but as the previous comments mention, it depends a lot what you are doing right now in your code. The linkaxes function is also very useful with multiple plots, but this will only keep the limits linked, it won't change the actual size of axes. linkprop may also not work for this in terms of e.g. 'Position' as it is only 2 elements of the position property you want to link, but other properties may work usefully.
Star Strider
on 8 Jan 2025
Experiment with changing thefirst and third values in the Position (OuterPosition) values for (c) to be the same as the corresponding Position values for (b).
Jorge Luis
on 8 Jan 2025
Star Strider
on 8 Jan 2025
I experimented with running your code. I cannot figure out the subplot calls, so changing the Position values is not possible. I cannot determine what needs to be changed.
Accepted Answer
More Answers (1)
%% PLOT FOR INTERFACE EARTHQUAKES
fsz=10; % 25 is way too big
color_text=[0.09 0.27 0.68];
figure
hAx1=subplot(4,4,[2,3,4,6,7,8,10,11,12]);
pos1=hAx1.Position;
xlim([-85 -60])
ylim([-60 10])
grid on
set(gca, 'FontName', 'Times New Roman', 'FontSize', fsz-3, 'FontWeight', 'bold', ...
'XColor', color_text, 'YColor', color_text, 'XTickLabelRotation', 0, ...
'LineWidth', 0.5, 'GridColor', [0.5, 0.5, 0.5], 'GridAlpha', 0.5);
%axis equal
axis square
%legend('Location','northeast','color',[0.97 0.96 0.96],'TextColor', [0 0.35 0.74],'EdgeColor',[0 0.35 0.74],'FontSize',10,'LineWidth',1);
%titl = strcat('(b)');
%title(titl,'FontSize',fsz+2,'color',color_text,'FontWeight', 'bold');
hAx2=subplot(4,4,[1,5,9]);
pos2=hAx2.Position;
xlim([0 75])
ylim([-60 10])
xticks([0, 25 50, 75]); % Set specific tick locations
xticklabels({'0', '25', '50' '75'}); % Set corresponding labels
%axis equal
xlabel('Z_{TOR} (km)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
ylabel('Latitude (°)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
%legend('Location','southeast','color',[0.97 0.96 0.96],'TextColor', [0 0.35 0.74],'EdgeColor',[0 0.35 0.74],'FontSize',10,'LineWidth',1);
grid on
set(gca, 'FontName', 'Times New Roman', 'FontSize', fsz-3, 'FontWeight', 'bold', ...
'XColor', color_text, 'YColor', color_text, 'XTickLabelRotation', 0, ...
'LineWidth', 0.5, 'GridColor', [0.5, 0.5, 0.5], 'GridAlpha', 0.5);
% Adjust overall figure appearance
set(gcf, 'Color', 'w')
%titl = strcat('(a)');
%title(titl,'FontSize',fsz+2,'color',color_text,'FontWeight', 'bold');
hAx3=subplot(4,4,[14,15,16]);
%pos1
%pos2
pos3=hAx3.Position
pos3([1,3])=pos1([1,3]);
%hAx3==gca
dL=0.06; dW=-2*dL;
pos=pos3+[dL 0 dW 0];
hAx3.Position=pos;
xlabel('Latitude (°)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
ylabel('Z_{TOR} (km)','FontSize',(fsz+1),'fontname','times','color',[0.04 0.57 0.84])
%titl = strcat('(c)');
%title(titl,'FontSize',fsz+2,'color',color_text,'FontWeight', 'bold');
xlim([-85 -60])
ylim([0 75])
grid on
%legend('Location','northeast','color',[0.97 0.96 0.96],'TextColor', [0 0.35 0.74],'EdgeColor',[0 0.35 0.74],'FontSize',10,'LineWidth',1);
yticks([0, 25 50, 75]); % Set specific tick locations
yticklabels({'0', '25', '50' '75'}); % Set corresponding labels
set(gca, 'FontName', 'Times New Roman', 'FontSize', fsz-3, 'FontWeight', 'bold', ...
'XColor', color_text, 'YColor', color_text, 'XTickLabelRotation', 0, ...
'LineWidth', 0.5, 'GridColor', [0.5, 0.5, 0.5], 'GridAlpha', 0.5);
%axis square reverse
set(gca, 'YDir', 'reverse');
% Adjust overall figure appearance
set(gcf, 'Color', 'w')
Had to arbitrarily adjust the bottom positions; the above is close, further refinement may be possible with more precision.
Not sure why the starting positions from the Position vector don't work correctly; something in the "behind the scenes" scaling with the square axes is probably the culprit.
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

