我在 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
找到这些属性,但没有成功)。
因此,我有两个问题:
- 为什么从 MATLAB 和 Java 的属性导出的图形窗口(可能这是轴框)的高度和宽度不相同(至少,它们在 Java 中是整数,在 MATLAB 中是 float )?
例如:
hf=figure('units','pixels'); ha=gca(hf);
set(ha,'units','pixels');
get(hf,'position')
get(ha,'position')
答案=
488 342 560 420
73.8000 47.2000 434.0000 342.3000`
而 BoxHeight=525
、BoxWidth=700
且移位始终为零(alignmentX=0.0
和 alignmentY=0.0
)。
- 如何在 MATLAB 使用 Java 中获取绘制的窗口轴的确切大小和位置?
最佳答案
在 MATLAB 中,figure
和 axes
都有一个名为 Position
的属性,但这不是一回事:
get(hf,'position')
会给你 position of the figure window on screen .
get(ha,'position')
将返回 position of the axes within the figure window .
因此,代码的输出
hf=figure('units','pixels');
ha=gca(hf);
set(ha,'units','pixels');
hfPos = get(hf,'position')
haPos = get(ha,'position')
答案=
hfPos = 520 378 560 420
haPos = 73.8000 47.2000 434.0000 342.3000
必须这样解释:
但是,我不知道为什么 get(ha,'position')
返回 float 。
在我的系统(Win7 Pro、MATLAB R2016a、Java 1.7.0_60-b19)上,以下代码发出警告:
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.
因此我不会依赖它。相反,我会使用上面的信息来获取在 MATLAB 中绘制的轴的大小和位置。
关于java - 如何获取JFrame中轴框的边界?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39466811/