Why won't my axes position change stick?

9 views (last 30 days)
Daniel Ko
Daniel Ko on 24 Aug 2019
Answered: Asvin Kumar on 28 Aug 2019
Hello,
I am trying to copyobj a heatmap (imagesc in an axes with a colorbar) into another figure and then reposition them, byt my position declarations seem to fail with no errors - can I have some insight as to how to solve this please?
f is a figure with just the heatmap and a colorbar, f.Children(2) being the axes and f.Children(1) being the colorbar. My f.Children(2).Position does not seem to stick. I tried using set(). Also, this does not seem to happen when I move the colorbar and the re-positioning works when I go step by step using the debugger, but not when I just run the script.
K>> f.Children(2)
ans =
Axes with properties:
XLim: [-90 90]
YLim: [-90 90]
XScale: 'linear'
YScale: 'linear'
GridLineStyle: '-'
Position: [0 0 0.9511 1.0000]
Units: 'normalized'
Show all properties
K>> [left, bottom, xFigS, yFigS]
ans =
0.0500 0.1000 0.4250 0.8000
K>> f.Children(2).Position = [left, bottom, xFigS, yFigS]
f =
Figure (1) with properties:
Number: 1
Name: ''
Color: [0.9400 0.9400 0.9400]
Position: [618 155 1200 800]
Units: 'pixels'
Show all properties
K>> f.Children(2).Position
ans =
0 0 0.9511 1.0000
  4 Comments
Daniel Ko
Daniel Ko on 24 Aug 2019
I am not sure what SRQ and TMW is sorry - I'm new here! Could you explain? Is it a way to contact Mathworks?
dpb
dpb on 24 Aug 2019
TMW--The MathWorks and SRQ--> Service Request. There is a "contact us" link at the top (the telephone receiver icon) you can use.

Sign in to comment.

Answers (1)

Asvin Kumar
Asvin Kumar on 28 Aug 2019
Use the drawnow command while setting or getting positions of any graphics objects. This makes sure that things are in sync as the two are running on different threads.
For best practice, use drawnow before asking for position of any object because it forces previous updates that haven’t reflected yet.
Here’s the documentation for more information: https://www.mathworks.com/help/matlab/ref/drawnow.html

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!