what does the four vector mean in matlab legend 'Position'?
조회 수: 79 (최근 30일)
이전 댓글 표시
I use the line:
leg = legend('Ionisation','Recombination');
pos = get(leg,'Position')
But get returned the answer:
pos =0.638988095238095,0.209126984126984, O.257142857142857,0.1
Can I ask what this means because this not the positions on the axes because when you look by eye it seems incorrect...
All I want to do is find the location (on the axes of the graph) of the bottom left corner so I can add another text box below with a string in it...
Thanks in advance MA
댓글 수: 0
답변 (4개)
Azzi Abdelmalek
2013년 7월 3일
pos(1) and pos(2) are the coordinate of the legend windows
pos(3) and pos(4) are width and height of this windows
댓글 수: 3
Azzi Abdelmalek
2013년 7월 4일
To understand try:
x0=0;
y0=0;
width=0.25;
height=0.25;
plot(1,1,2,2);
legend({'a','b'},'position',[x0 y0 width height])
change the position x0, and y0 then run again
x0=0.5;
y0=1
legend({'a','b'},'position',[x0 y0 width height])
x0,y0 are the coordinate of the left down corner of the legend windows
Malek Barhoush
2020년 10월 24일
x0=0;
y0=0;
width=0.25;
height=0.25;
plot(1,1,2,2);
legend({'a','b'},'position',[x0 y0 width height])
Walter Roberson
2013년 7월 4일
In order to understand the coordinates, you need to get() the Units property. Units can be any of several things, but in my experience the three that are used the most are "normal", "pixel", and "data".
Pixel is a measurement in pixels; fractional pixels are allowed.
Normal is based on fractions of the containing object, 0 being none of the object and 1 being the entire object. For example 'normal' and 0.3 as an axis position would mean 3/10 of the way along (from the left) the containing figure (or uipanel)
Data is data coordinates, based around the current xlim, ylim, or zlim. For example in your call
plot(1,1,2,2)
the 1's and 2's are in data coordinates.
If a graphics object has no Units property but has a Position property, then the graphics object is locked into Data coordinates; those kinds of graphics objects must be children of an axes.
댓글 수: 0
Jan
2013년 7월 4일
편집: Jan
2013년 7월 4일
You can learn more about the position by experimenting:
leg = legend('Ionisation','Recombination');
pos = get(leg,'Position');
pause(1);
set(leg, 'Position', [0.64, 0.21, O.25, 0.1]);
pause(1);
set(leg, 'Position', [0.74, 0.21, O.25, 0.1]);
pause(1);
set(leg, 'Position', [0.64, 0.31, O.25, 0.1]);
pause(1);
set(leg, 'Position', [0.64, 0.21, O.35, 0.1]);
pause(1);
set(leg, 'Position', [0.64, 0.21, O.25, 0.2]);
pause(1);
set(leg, 'Position', [0.0, 0.0, 1.0, 1.0]);
pause(1);
set(leg, 'Position', [0.5, 0.5, 0.4, 0.4]);
댓글 수: 0
Martin
2013년 7월 4일
댓글 수: 2
Jan
2013년 7월 4일
편집: Jan
2013년 7월 4일
The limits of the axes do not matter, whan you use 'normalized' posiotions. Matlab converts the absolute position on the screen automatically for you. This code writes the string to the upper right corner without knowing the data size:
axes('XLim', cumsum(rand(1, 2)), 'YLim', cumsum(rand(1, 2)));
H = text(0.9, 0.9, 'Hello', 'VerticalAlignment', 'top', ...
'HorizontalAlignment', 'right', ...
'Units', 'normalized');
drawnow;
% Obtain the position in data units if wanted:
set(H, 'Units', 'data');
dataPos = get(H, 'Position');
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!