what does the four vector mean in matlab legend 'Position'?
79 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (4)
Azzi Abdelmalek
el 3 de Jul. de 2013
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 comentarios
Azzi Abdelmalek
el 4 de Jul. de 2013
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
el 24 de Oct. de 2020
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
el 4 de Jul. de 2013
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 comentarios
Jan
el 4 de Jul. de 2013
Editada: Jan
el 4 de Jul. de 2013
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 comentarios
Martin
el 4 de Jul. de 2013
2 comentarios
Jan
el 4 de Jul. de 2013
Editada: Jan
el 4 de Jul. de 2013
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');
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!