Set the Subplot Apsect Ratio Manually
Mostra commenti meno recenti
hi, I have a problem with setting the AR of one of my subplots. lets try to make this more understandable. first of all, here is a part of the code
scrsz = get(0,'ScreenSize');
figure('Position',[1 scrsz(2) scrsz(3) scrsz(4)]);
s1=subplot(2,6,1:5); hold on; grid on; box on; axis([totminx 1.02 totminz totmaxz]);
dx=1.02-totminx;
dz=totmaxz-totminz;
h=0.3412;
w=h*dx/dz;
set(s1,'FontSize',15, 'Position', [0.13 ,0.5838 ,w ,h])
plot(poly(:,1), poly(:,2), 'k', 'LineWidth', 2)
plot(x1, z1, 's', 'MarkerFaceColor', 'r', 'MarkerEdgeColor', 'r', 'MarkerSize', 5);
ok, what i want to get is original proportions for the plot, meaning that the dist between 0-0.1 will look the same in the x and y axis. (does not mean a square image!)
also, i want to do this manually by changing the position of the subplot itself.
i want to do this because when i use the simple way of: set(s1, 'DataAspectRatio', [ 1 1 1]) other annotations that i add afterwards are not connected and seem to be floating, this is because the "DAR" doesn't change the subplot's position.
hope that you can at least understand my question now :( sorry about the confusion caused.
thanks Noa
5 Commenti
Daniel Shub
il 19 Set 2012
Using axis equal adjusts the limits on the x and y (and possibly z) dimensions. It doesn't change the size/position of the subplot. What exactly doesn't work with set(gca, 'Position', [x,y,w,h])
noa
il 19 Set 2012
Malcolm Lidierth
il 19 Set 2012
Modificato: Malcolm Lidierth
il 19 Set 2012
@noa As you have, but do not used normalised units - Use centimeters etc instead.
set(gca, 'Units', .....
noa
il 19 Set 2012
Daniel Shub
il 19 Set 2012
At this point I am going to flag this question. Noa, please edit the question to provide some code and ideally an image that demonstrates the problem and a clear and concise explanation of what you see and what you expect to see.
Risposta accettata
Più risposte (2)
Daniel Shub
il 19 Set 2012
I think what you are looking for is:
set(gca, 'PlotBoxAspectRatio', [1,1,1])
1 Commento
noa
il 19 Set 2012
Daniel Shub
il 19 Set 2012
Modificato: Daniel Shub
il 19 Set 2012
I think the problem is that the default unit of an axis object is normalized and the default unit of a figure object is pixels. This means that if the figure is not square than an axis with a position of [x, y, a, a] will not be square. If you want an axis with a position of [x, y, a, a] to be square, or more accurately if you want [x, y, a, b] to have an aspect ratio of a/b, then you need a square figure. Assuming that get(0, 'MonitorPositions') returns something meaningful (see: dual monitor support), then you should be able to do
pos = get(0, 'MonitorPositions');
set(gcf, 'Position', [1, 1, 0.5*min(pos(1, 3:4)), 0.5*min(pos(1, 3:4))]);
set(gca, 'Position', [0.1, 0.1, 0.8, 0.8]);
While I agree that afterwards a set(gca, 'PlotBoxAspectRatio', [1,1,1]), should have no effect, on my system it does. There is a slight change in the tight inset, but I don't think this affects the size of the axis directly.
Categorie
Scopri di più su Graphics Object Properties in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!