我在previous question上得到了答案。但是,要获得这些坐标(axis equal
的情况下轴箱的大小和位置),我们需要进行一些相对繁琐的计算。但是,由于MATLAB图形基于Java,我们可以访问Java属性。
我发现如果我们在MATLAB中使用它:
jFrame = get(gcf,'JavaFrame');
BoxHeight = jFrame.getAxisComponent.getHeight;
BoxWidth = jFrame.getAxisComponent.getWidth;
我们可以获得图形窗口的宽度和高度(也许这可以与轴的组件相关联)。但在像素单位的情况下,它们与get(gcf, 'Position')
或get(gca, 'Position')
的值不同。我不是Java专家(我也试图使用Altman findjobj
找到这些属性,但未成功。)
因此,我有两个问题:
例如:
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`
而BoxHeight=525
,BoxWidth=700
和转变始终为零(alignmentX=0.0
和alignmentY=0.0
)。
答案 0 :(得分:1)
在MATLAB中,axes
和Position
都有一个名为get(hf,'position')
的属性,但它不是一回事:
get(ha,'position')
将为您提供position of the figure window on screen
hf=figure('units','pixels');
ha=gca(hf);
set(ha,'units','pixels');
hfPos = get(hf,'position')
haPos = get(ha,'position')
将返回position of the axes within the figure window。
因此,代码的输出
hfPos = 520 378 560 420
haPos = 73.8000 47.2000 434.0000 342.3000
ans =
get(ha,'position')
必须像这样解释:
但是,我不知道为什么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.
会返回浮点数。
在我的系统上(Win7 Pro,MATLAB R2016a,Java 1.7.0_60-b19),以下代码发出警告:
None
因此我不会依赖它。相反,我会使用上面的信息来获得在MATLAB中绘制的轴的大小和位置。