暂时展开(最大化)子图图,然后将其折回 [英] Expand (maximise) subplot figure temporarily — then collapse it back

查看:108
本文介绍了暂时展开(最大化)子图图,然后将其折回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常在Matlab中,我们会绘制带有许多子图轴的图形,但是它们都很小.

Often in Matlab we would plot a figure with many subplot axes, but they are all tiny.

在流行的UX范例中,您希望能够双击这样的小图,以便在整个屏幕空间中进行仔细观察.

In the prevalent UX paradigm, you would expect to be able to double-click such a small plot to have a closer look using the entire screen space.

通常,这就是我避免使用subplot的原因,而是绘制许多单独的图形-因此,我可以在屏幕上四处移动它们,并双击其标题栏(在Windows上),从而使图形最大化至全屏显示. (再次双击,它会恢复为正常大小.)

Typically this is the reason I avoid using subplot, but plot many individual figures instead — so I can move them around on the screen and double-click on their titlebars which (on Windows) maximises the figure to full screen. (Double-click again, and it returns to its normal size.)

但是,subplot的优点是,一组图被分组在一个面板中.当我绘制许多这样的组时(每个组都有十二个单独的子图轴),要处理这么多的单个图变得很困难.

However, the advantage of subplot is that the set of plots is grouped in one panel. When I'm plotting many such groups (each with a dozen separate subplot axes), having that many individual figures becomes hard to work with.

那么,有没有办法在Matlab中启用此功能?

So, is there a way to enable this functionality in Matlab already?

推荐答案

组合这些 三个 帖子,这就是我所拥有的到目前为止:

Combining parts of these three posts, here's what I have so far:

h = subplot(2,2,1);
line(1:10, rand(1,10));
set(h, 'buttondownfcn', ['h=gca; hc = copyobj(h, gcf);' ...
    'set(hc, ''Units'', ''normal'',' ...
    ' ''Position'', [0.05 0.1 0.8 0.85],' ...
    ' ''buttondownfcn'', ''delete(gca)'');']);

这并不完美,但是可以.

It's not perfect, but it works.

单击轴:

点击展开的轴,它消失了:

Click on the expanded axes, and it disappears:

请注意,这仍然允许您平移,缩放和旋转3D"结果轴.选择箭头工具实际上会进入编辑模式",因此最好取消选择您正在使用的工具.例如:如果您正在放大,请再次单击放大图标以取消选择该工具.然后单击将折叠"轴的爆炸.

Note that this still allows you to pan, zoom, and "rotate 3D" the resulting axes. Selecting the arrow tool actually enters "Edit Mode", so it's better to unselect the tool you are using instead. For example: if you were zooming in, click on the zoom-in icon again to deselect the tool. Clicking will then "collapse" the blow-up of the axes.

到目前为止,局限性在于您有时可以看到下面的基本小子图轴的一部分.如果有人可以推荐一种优雅的隐藏方式,那将是一个很好的改进.

The limitation so far is that you can sometimes see parts of the underlying little subplot axes underneath. If someone can recommend an elegant way to hide them, that would be a nice improvement.

编辑此答案(使用uipanel以防止其他内容显示出来),我现在将解决方案变成了这样:

EDIT Learning from this answer (using a uipanel to prevent other contents from showing through), I now have turned the solution into this:

gcaExpand.m:

function gcaExpand

    set(copyobj(gca, uipanel('Position', [0 0 1 1])), ...
       'Units', 'normal', 'OuterPosition', [0 0 1 1], ...
       'ButtonDownFcn', 'delete(get(gca, ''Parent''))'); 

end

gcaExpandable.m:

function gcaExpandable

    set(gca, 'ButtonDownFcn', [...
        'set(copyobj(gca, uipanel(''Position'', [0 0 1 1])), ' ...
        '    ''Units'', ''normal'', ''OuterPosition'', [0 0 1 1], ' ...
        '    ''ButtonDownFcn'', ''delete(get(gca, ''''Parent''''))''); ']);

end

第一个立即扩展当前图.第二个添加了在绘图上单击以展开它的功能.在这两种情况下,再次单击均可使一切恢复正常.

The first one expands the current plot immediately. The second one adds the functionality where clicking onto the plot expands it. In both cases clicking again returns things back to normal.

我将它们与我日常使用的所有其他自定义Matlab函数放到了目录中.上面的内容也可以包含在要发送的函数中.

I've placed them into the directory with all my other custom Matlab functions that I'm using on a day-to-day basis. The above can also be included in functions to be sent out.

最初,我打算编写一个自定义版本的subplot,该版本自动应用gcaExpandable,但是没有用,因为像plot这样的命令会擦除ButtonDownFcn属性(以及所有其他属性) (位置除外).根据此答案,我们可以通过将NextPlot更改为'replacechildren'来避免重置那些属性,但这有其一面效果.例如,plot不再自动缩放轴.因此,到目前为止,最干净的解决方案似乎如上所述.

Initially, I was going to write a custom version of subplot that applied gcaExpandable automatically, but that didn't work, because commands like plot erase the ButtonDownFcn property (as well as all other properties, except the position). According to this answer, we can avoid resetting those properties by changing the NextPlot to 'replacechildren', but that has side-effects. For example, plot no longer automatically rescales the axes. Therefore, the cleanest solution so far seems to be as above.

这篇关于暂时展开(最大化)子图图,然后将其折回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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