4
votes

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

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.

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.)

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.

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

1
This recent post seems related or even providing an answer: stackoverflow.com/questions/25160853/…Nras
There are files such as this mathworks.com/matlabcentral/fileexchange/35511-position-figure on matlab fileexchange. They align figures on a panel the same way subplots are aligned within one figure.Nras

1 Answers

1
votes

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.

enter image description here

Click on the axes:

enter image description here

Click on the expanded axes, and it disappears:

enter image description here

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.


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.

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.

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.