为什么独立的子图相互覆盖?为什么绘图顺序很重要? [英] Why do independent subplots overwrite each other? Why is the order of plotting important?

查看:150
本文介绍了为什么独立的子图相互覆盖?为什么绘图顺序很重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个gui,它需要精确定位一些子图:

I'm writing a gui which requires to exactly position some subplots:

h = figure('Units','pixels','Position',[1920 432  1881 982]*0.5);

ax.VSize = 815.3800*0.5
ax.VOffset = 48.9228*0.5
ax.HSize = 1.8063e+03*0.5
ax.HOffset = 56.4480*0.5

subax.VSize = 0.33*(ax.VSize-3*ax.VOffset);
subax.HSize = ax.HSize;
subplot(313,'units','pixels','Position',[ax.HOffset ax.VOffset ax.HSize subax.VSize ])
subplot(312,'units','pixels','Position',[ax.HOffset 2*ax.VOffset+subax.VSize subax.HSize subax.VSize])
subplot(311,'units','pixels','Position',[ax.HOffset 3*ax.VOffset+2*subax.VSize subax.HSize subax.VSize])

这给了我想要的结果:

但是,当我将子图的顺序更改为:

However, when I change the order of the subplots to:

subplot(311,'units','pixels','Position',[ax.HOffset 3*ax.VOffset+2*subax.VSize subax.HSize subax.VSize])
subplot(312,'units','pixels','Position',[ax.HOffset 2*ax.VOffset+subax.VSize subax.HSize subax.VSize])
subplot(313,'units','pixels','Position',[ax.HOffset ax.VOffset ax.HSize subax.VSize ])

我只绘制了最后一个子图:

I just get the last subplot plotted:

我真的不明白为什么会这样吗? 为什么子图相互覆盖?

I really don't see why this is happening? Why do the subplots overwrite each other?

不幸的是,打印顺序对我来说很重要,那么我该如何解决呢?

Unfortunately the order of plotting is important to me, so how can I fix this?

有趣的是,我无法用其他数量或排列的子图来重现该问题,例如:

Funnily, I can't reproduce the problem with another number or arrangement of subplots, like:

subax.VSize = 0.5*(ax.VSize-2*ax.VOffset);
subax.HSize = 0.5*(ax.HSize-2*ax.HOffset);
subplot(221,'units','pixels','Position',[ax.HOffset 2*ax.VOffset+subax.VSize subax.HSize subax.VSize])
subplot(222,'units','pixels','Position',[2*ax.HOffset+subax.HSize 2*ax.VOffset+subax.VSize subax.HSize subax.VSize])
subplot(223,'units','pixels','Position',[ax.HOffset ax.VOffset subax.HSize subax.VSize ])
subplot(224,'units','pixels','Position',[2*ax.HOffset+subax.HSize ax.VOffset subax.HSize subax.VSize ])

推荐答案

原因仍不完全清楚,但

The reason is still not entirely clear to me, but here is said:

对于文档,如果您覆盖子图的区域,它将删除 现有的并创建一个新的. AFAIK无法避免这种情况 行为.有一个带有subplot()的叠加轴的示例 文件;请注意,它通过指定轴来避免这种情况 带有轴,而不是另一个子图.

Per the doc, if you overwrite the area of a subplot, it deletes the existing one and creates a new one. AFAIK there's no way to avoid this behavior. There's an example of an overlaying axes with subplot() in the documentation; note that it avoids this by specifying that axes with axes, not another subplot.

如果仅参考两个轴,则可能会与您相处 创建保存后的手柄之后.

You can probably get by with yours if you only refer to the two axes with the saved handles once they're created.

建议的解决方案也适用于我的情况:

The suggested solution also works in my case:

s(1) = subplot(311,'units','pixels')
s(2) = subplot(312,'units','pixels')
s(3) = subplot(313,'units','pixels')

set(s(1),'Position',[ax.HOffset 3*ax.VOffset+2*subax.VSize subax.HSize subax.VSize])
set(s(2),'Position',[ax.HOffset 2*ax.VOffset+subax.VSize subax.HSize subax.VSize])
set(s(3),'Position',[ax.HOffset ax.VOffset ax.HSize subax.VSize ])

但是,当我指定每个子图的确切位置时,子图的整个目的都消失了,所以我只使用:

However, as I specify the exact position of every subplot, the whole purpose of subplots is gone, so I will just use:

axes('units','pixels','Position',floor([ax.HOffset 3*ax.VOffset+2*subax.VSize subax.HSize subax.VSize]));
axes('units','pixels','Position',floor([ax.HOffset 2*ax.VOffset+subax.VSize subax.HSize subax.VSize]));
axes('units','pixels','Position',floor([ax.HOffset ax.VOffset 0.96*hsize subax.VSize]));

反正奇怪的问题.

这篇关于为什么独立的子图相互覆盖?为什么绘图顺序很重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆