keep exact position of subplot axes
Afficher commentaires plus anciens
I want to plot three 2D projections of some 3D data. For compatibility with other images (our convention) I need to keep the position of the corresponding axes identical - see Fig.
Is there any (simple) way to do this? The layout in the image is the result of interactive manipulation with the size of the image - not entirely convenient :-(
'Subplot' or 'nexttile' with tiledlayout(2,2,'TileSpacing','none'); can't do it.
Of course, it would be possible to plot all the data in one axis (after a simple recalculation of the coordinates), but the advantage of individual axes for each (sub)projection would be lost ...

function plot3x2D
close all
clear all
NN=10;
x=rand(1,NN);
y=rand(1,NN);
z=rand(1,NN);
val=rand(1,NN);
figure; hold on
axis off
a11=axes('pos',[0.05 0.5 0.45 0.45],'XaxisLocation','top',"Xdir",'reverse');
hold on
scatter(x,y,val*200,val,'filled','Markerfacealpha',0.6);
axis equal
set(gca,'xlim',[0 1]);
set(gca,'ylim',[0 1]);
box on
a12=axes('pos',[0.5 0.5 0.45 0.45],'Yaxislocation','right');
hold on
scatter(z,y,val*200,val,'filled','Markerfacealpha',0.6);
axis equal
set(gca,'xlim',[0 1]);
set(gca,'ylim',[0 1]);
box on
a21=axes('pos',[0.05 0.05 0.45 0.45],"Xdir",'reverse');
hold on
scatter(x,z,val*200,val,'filled','Markerfacealpha',0.6);
axis equal
set(gca,'xlim',[0 1]);
set(gca,'ylim',[0 1]);
box on
aa=1;
end
%==============eof==================
Réponses (1)
To clarify, when you say "position" do you mean the location of the subplot axes in the figure window, the limits of the axes (so that all three are "looking at" the same section of the Cartesian plane), both of those, or something else?
If you mean the locations in the figure window, nothing that I can see in your code ought to change those. The axis equal calls might change how much of the axes "screen real estate" is actually used for the plotting area, but it shouldn't change the Position property of the axes.
ax = axes;
plot(ax, 1:10, (1:10).^2)
posBefore = ax.Position
axis equal
posAfter = ax.Position
isequal(posBefore, posAfter)
If you mean the limits of the axes, so zooming into one zooms into the others and the same with panning, take a look at the linkaxes function.
If you mean something else when you say "position", please explain in more detail what quality of the three axes you want to remain unchanged and what manipulations you're planning to perform on the axes (panning, zooming, changing the view, etc.)
Catégories
En savoir plus sur Subplots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
