File Exchange

image thumbnail

Distribute figures

version 1.17 (548 KB) by

This function can distribute figures on different parts of the screen(s).

22 Downloads

Updated

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Are you tired of moving your figures around to see them all? This function does it all for you! It can distribute in all parts of the screen, include Simulink figures or not and a whole lot more! It also supports secondary monitor(s) where the figures can be distributed.
>>>> A sample image can be found here: http://oi60.tinypic.com/9amydc.jpg <<<<<
The function calls needed to distribute in the shown pattern above is only:

distFig('Pos','NW','Only',1);
distFig('Pos','SW','Cols',3,'Only',(2:4));
distFig('Pos','NE','Rows',2,'Only',5);
distFig('Pos','NE','Rows',2,'Cols',2,'Only',[6,7],'Offset',2,'transpose',true);
distFig('Pos','SE','Rows',2,'Cols',4,'Only',(8:11));
distFig('Pos','SE','Rows',3,'Cols',2,'Not',(1:11),'Offset',3);

(Don't worry - it looks complicated, but by executing distFig(); the figures will also be nicely distributed. :) ) Also, there are two tutorials included to guide you through the various features.

The function supports all resolutions (also different resolutions on different monitors). It has been made using MATLAB 2015a and will thus not work properly for version 2014a and previous due to the changes in the figure handle system in version 2014b a newer releases.

The function also detects new updates automatically, but this feature is very beta, so it might contain bugs. It can easily be disabled without affecting the function, if it causes problems. Please report any errors encountered with the function. :)

Syntax:

distFig(...,'Screen',Value)
distFig(...,'Position',Value)

distFig(...,'Rows',Value)
distFig(...,'Columns',Value)

distFig(...,'Not',Value)
distFig(...,'Only',Value)
distFig(...,'Offset',Value)

distFig(...,'Adjust',Value)
distFig(...,'Extra',Value)
distFig(...,'Menu',Value)
distFig(...,'Transpose',Value)
distFig(...,'Simulink',Value)
distFig(...,'Tight',Value)
distFig(...,'Scale',Value)
distFig(...,'ScaleOrigin',Value)
distFig(...,'FreezeSize',Value)
distFig(...,'Order',Value)

Description:

distFig(...,'Screen',Value) assigns where the figures will be distributed. Synonyms for 'Screen' are 'Scr' and 'S'. Value can be:
'C' / 'Center' (Default)
'W' / 'West' / 'L' / 'Left'
'E' / 'East' / 'R' / 'Right'
'N' / 'North' / 'T' / 'Top'
'S' / 'South' / 'B' / 'Bottom'
'Main' / 'Primary'
'Ext' / 'External' / 'Secondary'

distFig(...,'Position',Value) assigns in which part of the screen the figures will be distributed. Synonyms for 'Position' are 'Pos' and 'P'. Value can be:
'C' / 'Center' (Default)
'W' / 'West' / 'L' / 'Left'
'E' / 'East' / 'R' / 'Right'
'N' / 'North' / 'T' / 'Top'
'S' / 'South' / 'B' / 'Bottom'
'NW'
'NE'
'SW'
'SE'

distFig(...,'Rows',Value) assigns how many rows the figures will be distributed on. Synonyms for 'Rows' are 'R'. Value can be:
1...n
'Auto' / -1
'Auto' indicates that it automatically calculates the number of required rows.

distFig(...,'Columns',Value) assigns how many rows the figures will be distributed on. Synonyms for 'Columns' are 'Cols' and 'C'. Value can be:
1...n
'Auto' / -1
'Auto' indicates that it automatically calculates the number of required columns.

distFig(...,'Not',Value) excludes specified figures from the distribution list. Value must be an array with the excluded figure numbers. The default value is []. The input argument 'gcf' (get current figure) can be used as well.

distFig(...,'Only',Value) does only distribute specified figures. Value must be an array with the figure which will be distributed. The default value is []. The input argument 'gcf' (get current figure) can be used as well.

The remaining features are described in the file.

Comments and Ratings (56)

brayan torres

Great Function. Tight was not performing as I expected for me. However
changing:
set(gca_Temp,'Position',[get(gca_Temp,'TightInset')*eye(4,2),1 - get(gca_Temp,'TightInset') * [1,0,1,0;0,1,0,1]']);
to:
set(gca_Temp,'LooseInset',get(gca_Temp,'TightInset'));
is perfect.
Thanks for the function.

tahir anwar

hello friends i have to analyzed harmonic inject by ups in secondary electric distribution system and simulate in matlab anyone who can simulate secondary distribution system with ups in consumers houses >>>>>>>>> plz help me .

@arnold: Hi. You can simply add the colorbar after you've used distFig. This will allow matlab to add the colorbar and adjust the axis, so you'll be able to see it. Like so:
surf(X,Y,Z);
distFig('tight',true);
colorbar;

Instead of this:
surf(X,Y,Z);
colorbar;
distFig('tight',true);

arnold

arnold (view profile)

hi Anders,
is there a robust way to handle colorbars including their labels? 'tight = true' doesn't really to a good job of making sure the colorbars are still readable but not using tight results in too much waste in space.

regards
Arnold

Rex

Rex (view profile)

Amazing! Thanks Anders.

Nice job!

grwa

grwa (view profile)

An option for keeping the aspect ratio of a figure fixed, while still allowing automatic resizing, would be pretty awesome.

Ben

Ben (view profile)

Wonderful job definitely worth a 5-star rating!

Anthony

@arnold: Hi. Okay, I'll take a look at it in the next update. I've encountered some bugs with the 'tight' command as well, so I'll make sure it's working properly.

arnold

arnold (view profile)

Hi Anders,

the 'tight' property doesn't work properly if one uses suptitle (and I use it a lot). distFig then cuts of the xlabel of plots.

kind regards
arnold

Luke

Luke (view profile)

So very useful... Thank you Anders

@Alia: I'm not supporting MATLAB 2014a and previous releases due to the changes in the graphics structure within the 2014b and newer releases. Sorry :|

Alia

Alia (view profile)

Hello,

I still have this error msg:
Attempt to reference field of non-structure array.

Error in distFig (line 454)
Fig_Number = {Fig_Object.Number};

Error in Sample (line 28)
distFig('Pos','NW','Only',1,'Tight',true);

I am using MatlabR2014a, how is it possible to solve it

@Michael: Thanks! And sorry for the late answer. Sure, I'll make sure to add that to the next update, which will follow soon. :)

Michael

Hello Anders,
Impressive work! It's a very nice and handy function. Would you consider adding an option to not resize figures, but distribute them with their current size? That would help a lot.
Thanks,
Michael

I don't know why I got monitor matrix which didn't have an origin at [1, 1]. I had 'dbstop if error' and ran get(0,'MonitorPositions') at dbstop. I couldn't reproduce it either since there is no error.

Okay, perfect! Also, you can see that your monitors are detected "correctly" this time. I don't know how you got your previous monitor matrix, which hadn't got an origin at [1,1].

Now my extended display works also. Thanks!

Yes, I was a bit surprised to see that I had only one row when I checked monitor. After restarting the matlab, the monitor matrix becomes:
Monitors =

-1365 1 1366 768
1 1 1920 1200

Okay, it seems like you only have a single monitor. The number of rows in the monitor matrix is the number of monitors:

[Origin_x , Origin_y , Width , Height]

Mine yields:

[1,1,1920,1080
-1919,1,1920,1080]

Can you describe your setup?

Btw. MATLAB does not recognize changes in the monitor configuration, AFTER it has been started. So if you plug in your monitor AFTER you started MATLAB, it will not detect it - so try and restart MATLAB and see if that works.

Yes, I got a warning message. Here is the monitor matrix.
Monitors =

1 1 1920 1080
Ke

@Chad: Thanks! :D

@Ke Wang: Yearh - you should be able to. Does you come with a warning message? Can you post your monitor matrix again (Monitors = get(0,'MonitorPositions');)? (If it has changed?)

You can see my setup here, where I made a brief description of how to distribute to external monitor(s). http://s000.tinyupload.com/index.php?file_id=63083430746980020338

Hello Anders, I wonder if I can distribute figures to extended displays. It seems that the function doesn't consider it as external monitor and couldn't find it.

Chad Greene

Chad Greene (view profile)

That is the finest FEX submission icon I have ever seen. Well done.

Erik

Erik (view profile)

@Ke Wang: Thanks a lot! :D I thought it might help with some of the features. :) I plan on making more tutorials soon.

It works very well now. Thanks for the function!

And the tutorial is great!

@Ke Wang: Hmm - that's weird. Usually the primary monitor has origin in [1,1], but yours seem to be located at [1,121]. I couldn't reproduce your settings, as I instead got:

-1365 153 1366 768
1 1 1920 1080

But I've just uploaded a new version, where the primary monitor is detected by minimizing the absolute sum of the two first columns, so it should work for you now, if you just download the latest one. :)

Thanks for your quick reply. Here is the matrix:
Monitors =

-1365 273 1366 768
1 121 1920 1080

Ke

@Ke Wang: All right - I don't know what causes that. Can you evaluate the following in your Matlab workspace and send me the resulting matrix:

Monitors = get(0,'MonitorPositions');

Monitors is a (n x 4) matrix, where n is the number of monitors you have.

I have tried Sample.m in MATLAB2014b and got following error:
Warning: Screen 'C' could not be found!
> In distFig at 382
In Sample at 21
Index exceeds matrix dimensions.

Error in distFig (line 408)
x = round(linspace(Limit{2}(1),Limit{2}(2),Cols + 1) * Monitor(3)) + 1;

Error in Sample (line 21)
distFig('Pos','NW' , 'Only',1);

408 x = round(linspace(Limit{2}(1),Limit{2}(2),Cols + 1) * Monitor(3)) + 1;

@Ramin: The function will not work for Matlab version 2014a and previous. This is due to the massive overhaul of the graphics handle system in 2014b and forward.
You can try and rewrite the lines that are not working, as I'll not support version 2014a and previous anymore - sorry. :)

Ramin Rajabioun

running Sample.m produces an error like this on my MATLAB 2014a:

Attempt to reference field of non-structure array.

Error in distFig (line 322)
Fig_Number = {Fig_Object.Number};

Error in Sample (line 21)
distFig('Pos','NW' , 'Only',1);

@Mike: Thanks - so do I. ;)

Okay, thanks for the feedback and for finding and fixing the problem! :D I'll make sure to include it in the next version of it.

I've also stumbled upon a few bugs as well, which aren't working properly after the 2014b release, so I'll update it again soon.

Mike

Mike (view profile)

Very nice feature, I use it all the time :)

Had a little compatibility issue with the newly released R2014b. Since figure handles are no longer numbers but figure objects, the sort feature no longer works. Hence, the figures get distributed nicely, just not in the right order. I fixed this by accessing the Number property of the figure objects instead. (see below)

My code adaptation, first line of 'Generate figure list' section:
ORIGNAL CODE:
Fig_List = findall(0,'type','figure');

MY ADAPTATION:
Fig_Object = findall(0,'type','figure');
Fig_List = [Fig_Object.Number];

This way, Fig_List is a vector of numbers again that can be sorted a few lines below ;) Not sure if it's the neatest way, but works fine for me :)

@arnold: Can you send me an example code, where you are having the problem? Then I can take a look at it. :) (Btw. I've sent you a private message as well)

arnold

arnold (view profile)

hi anders.
I've integrated the 'tight' argument in many of my functions but just saw that it is cutting off any xlabel one adds to a boxplot... no idea why xlabels of boxplots are treated entirely different than those of other plots.

@arnold: I've just updated it again and now it should work. I didn't test it yesterday on 2014a as I didn't have acces to it, but now I have done that and fixed the error.

It is caused by the new way that the figure system is made in 2014b, which has been changed a lot! The only thing you should do is to download it again or just delete the line that is causing the error. :)

arnold

arnold (view profile)

@ Anders: thanks for the update. Unfortunately the function does not work anymore, no matter what type of figures are open. i.e. opening four figures, no content, then executing 'distFig' with no arguments. Gives the following error on 2014a:

Improper index matrix reference.

Error in distFig>@(n)(Figs(n).Number) (line 199)
Figs = sort(arrayfun(@(n) (Figs(n).Number),1:numel(Figs)));

Error in distFig (line 199)
Figs = sort(arrayfun(@(n) (Figs(n).Number),1:numel(Figs)));

@arnold: I've just updated the function to support the other function. The problem was that "fig()"; changed 'Units' to 'centimeters', whereas my function was using 'pixels'. Furthermore, I've added a new feature called distFig(...,'Tight',true/false), which can remove the whitespace around the figure like "fig();" - if that is what you're looking for. :)

And thanks for the feedback. :)

arnold

arnold (view profile)

for some reason 'distFig' can't deal with figures produced by 'fig' from the fileExchange, which is also a great tool:
http://www.mathworks.com/matlabcentral/fileexchange/30736-fig-the-exact-figure-size-and-no-white-space

The figures disappear from the screen even though they're still opened.

Anders

Anders (view profile)

Often i used to be both tired and depressed - but then I tried Quack Simonsen's mircale function. Now I feel much better - thanks Simonsen!

@Ivan: Sorry for the late response. Yes - the new function does support different screen resolutions. :)

Ivan

Does it support different screen resolutions? Or just 1920*1080?

Exactly what I was looking for and easy to use.

Tobias Olesen

Great funktion!

Tom

Tom (view profile)

Thanks!

Thanks. So I assume you would have preferred something like distFig('Position','Left','Screen','Right');?

Deborah

Nice function. Although I think it doesn't make any sense to accept multiple character input like 'r','l' since only the last input is used by the function.

Updates

1.17

Fixed a minor bug with the 'only' and 'not' features when using the 'gcf' input.

1.16

Added support for 'gcf' (get current figures) when using the 'only' and 'not' features.
Added features: 'Scale', 'ScaleOrigin', 'FreezeSize' and 'Order'.
Added additional warnings if external monitor(s) cannot be found.
Minor bug fixes.

1.15

Added a second tutorial and added an 'Adjust' feature.

1.14

Fixed a minor bug causing incorrect detection of primary monitor.

1.13

Added a tutorial file.

1.12

Added improved relative monitor detection.
Added exceptions for special function calls, which caused errors.
Fixed minor bugs.
Added automatically update feature system (First attempt of doing so, so it might cause bugs - please report these)

1.11

The function has been updated to support the new figure handle system of 2014b and 2015a (Prerelease). Minor bugs have been fixed as well.

1.10

Fixed a minor bug with the new figure handle system of 2014b.

1.9

Added support for the 2014b (pre)release. Also fixed a minor problem with the 'Units' property of the current axes.

1.8

Updated description

1.7

The whole function has been updated to support different screen resolutions along with other useful features.

1.6

A minor update

1.5

Added a few lines to the description.

1.3

Added the 'Rows' and 'Offset' properties and changed the input mode a more logical way.

1.2

Removed a misplaced "nargin".

MATLAB Release
MATLAB 8.5 (R2015a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video