imprecise position of figure

8 vues (au cours des 30 derniers jours)
painter wang
painter wang le 2 Sep 2018
Modifié(e) : jonas le 4 Sep 2018
Hi, I'm using figure handle to set the figure position:
hf = figure;
hf.Units = 'centimeters';
hf.Position = [10 10 18 18];
Then I check the position of the figure:
>>hf.Position
ans = 9.8690 9.1281 18.2563 18.7854
This is not what I set. Then I set it again:
hf.Position = [10 10 18 18];
>>hf.Position
ans = 10.0013 9.2604 17.9917 17.9917
Only after I tried once again, I got what I want:
hf.Position = [10 10 18 18];
>>hf.Position
ans = 10 10 18 18
Does anybody know the reason for this? This rather bothers me when I want to plot something with many details.
Thanks a lot.
Shizhu
  3 commentaires
painter wang
painter wang le 4 Sep 2018
Yes, I tried this too. But if you execute the first three lines and then the last line, it would be like what I have reported.
jonas
jonas le 4 Sep 2018
Modifié(e) : jonas le 4 Sep 2018
No, I cannot reproduce the issue regardless. The position is exactly and precisely as specified.
The only way I can reproduce something that resembles your issue, is if I first define the size and then move the figure manually (without changing the size). Calling the position property afterwards returns a marginally different size than originally specified, which is unexpected.
I am not qualified to answer this. However, speculatively, I would guess that the issue is that the size property is stored in normalized units, regardless of what you specify. When you specify the units in centimeters, it is therefore not exact. This is of course just me speculating.
Try executing the same code with normalized units, and see if you get the same result. For me, it resolved the issue so that the sequence:
hf = figure;
hf.Units = 'normalized';
hf.Position = [.5 .5 .2 .2];
--> move figure manually
hf.Position
returns the exact same size as specified, as opposed to if the size was specified in units of centimeters.
EDIT: After testing several different position values, I found that the issue you described is reproduced for some values but not all. Normalized units are always exact. I believe this would support my hypothesis described above.

Connectez-vous pour commenter.

Réponses (1)

Priyadarshini K R
Priyadarshini K R le 2 Sep 2018
  • You might be manually varying figure window size after running your code.
hf = figure;
hf.Units = 'centimeters';
hf.Position = [10 10 18 18];
  • If you do so figure window size will alter according to the manual figure window size.
  • So, when you print the below code, you'll get manually set figure window size. But, not the one you set in the actual code
>>hf.Position
  • In order to rectify this, better don't click on the figure window. Try this
hf = figure;
hf.Units = 'centimeters';
hf.Position = [10 10 18 18];
>>hf.Position
Hope it helps you!
  1 commentaire
painter wang
painter wang le 2 Sep 2018
Hi, thanks for the reply. But it seems not to be the case. I didn't click the figure window and the figure seems to change by itself. T_T

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by