I got the answer on my previous question. However, to get these coordinates (size and position of the axis box in the case of axis equal
) we need to do some relatively cumbersome calculations. However, since MATLAB graphics is based on Java, we can get access to Java properties.
I have found that if we use this in MATLAB:
jFrame = get(gcf,'JavaFrame');
BoxHeight = jFrame.getAxisComponent.getHeight;
BoxWidth = jFrame.getAxisComponent.getWidth;
we can obtain a width and height of figure windows (maybe this can be associated with the components of the axis). But they are differ from the value of get(gcf, 'Position')
or get(gca, 'Position')
in the case of pixel units. I'm not an expert in Java (I also unsuccessfully tried to find these properties using Altman's findjobj
).
Thus, I have two questions:
For example:
hf=figure('units','pixels'); ha=gca(hf);
set(ha,'units','pixels');
get(hf,'position')
get(ha,'position')
ans =
488 342 560 420
73.8000 47.2000 434.0000 342.3000`
whereas BoxHeight=525
, BoxWidth=700
and the shift is always zero (alignmentX=0.0
and alignmentY=0.0
).
In MATLAB, both a figure
and an axes
have a property called Position
, but it's not the same thing:
get(hf,'position')
will give you the position of the figure window on screen.get(ha,'position')
will return the position of the axes within the figure window.
Therefore, the output of the code
hf=figure('units','pixels');
ha=gca(hf);
set(ha,'units','pixels');
hfPos = get(hf,'position')
haPos = get(ha,'position')
ans =
hfPos = 520 378 560 420
haPos = 73.8000 47.2000 434.0000 342.3000
has to be interpreted like this:
However, I have no idea why get(ha,'position')
returns floating point numbers.
On my system (Win7 Pro, MATLAB R2016a, Java 1.7.0_60-b19) the following code issues a warning:
get(gcf,'JavaFrame');
Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the JavaFrame resource on the MathWorks web site.
Therefore I would not rely on using it. Instead, I would use the information above to obtain the size and position of the axes plotted in MATLAB.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With