Editor's Note: This file was selected as MATLAB Central Pick of the Week
MTIT
- creates a major title above all axes in a figure
- preserves the stack order of the axes
several options allow to fine-tune the position of the title and typical text property/value pairs may be used as additional input to further adjust its looks
see
> help mtit
for usage and a brief example for this small utility
us (2019). mtit: a pedestrian major title creator (https://www.mathworks.com/matlabcentral/fileexchange/3218-mtit-a-pedestrian-major-title-creator), MATLAB Central File Exchange. Retrieved .
1.1.0.0 | MTIT now preserves the stack of axis handles and returns in GCA the last used axis; version tag 13-Nov-2009 17:38:17 |
|
1.0.0.0 | help updated |
|
1) additional buil-in title modifier pairs
|
Inspired: mysubplot: subplots with major title, figtitle
Create scripts with code, output, and formatted text in a single executable document.
Nachiket Wadwankar (view profile)
Works like a charm!!
Thanks.
Setare Hajarolasvadi (view profile)
Alutsyah Luthfian (view profile)
I suggest an edit for the line 83 up to 86:
>> if all(cellfun(@ischar,varargin{1}))
>> vl(1)=false;
>> figh=gcf;
>> txt=varargin{1};
so that we can have a multiline super-title.
Kalel Rossi (view profile)
Nedgine Laurenceau (view profile)
Sorry, it's ok. good function
Nedgine Laurenceau (view profile)
I don't find this function. When I tap "help mtit", it's not found
Filipe Borges (view profile)
Awesome function! Is there a way to make the final figure not visible? Apparently it sets the visibility to "on" and I could no change it =/.
Adwait Kale (view profile)
Thank you!
Ricardo Queiros (view profile)
Abbas Orand (view profile)
KAE (view profile)
Does not seem to work correctly in R2017a (supertitle does not appear)
Patrick Bevington (view profile)
Apologies: This is only adds a space at the top and does not split the line. Solved a problem I had with the title covering part of the axis.
Patrick Bevington (view profile)
A work around for this function not being able to split tiles i.e. mtit({'Line1','Line2'}), is to first put a blank title over your first subplot. Example below:
figure(1)
subplot(2,2,1)
title({'',''})
subplot(2,2,2)
subplot(2,2,3)
subplot(2,2,4)
p=mtit('the BIG title')
Narayanan Rengaswamy (view profile)
Xiao (view profile)
hong-liang sun (view profile)
Simone (view profile)
Miles (view profile)
is there a way to turn off or erase the title once it's generated using mtit?
Arda Aksu (view profile)
you have some indent issues! :)
Sven (view profile)
Michael (view profile)
Robert (view profile)
Works great! NB. seems to be incompatible with new graphics in the 2014b release, hope you can modify it to sense the matlab release and operate accordingly.
Greg (view profile)
Vinitha (view profile)
Johann (view profile)
Awesome dude. Thanks. Works great.
Béla (view profile)
Thank you! Works great!
Adam (view profile)
Thanks. Great function, works well.
My only complaint is that line 136:
axes(oah);
causes a figure's 'Visible' property to be set to 'on' (I had turned it off to save time and resources). A better solution might be:
set(figure_handle,'CurrentAxes',axes_handle)
which updates the current axis without changing the state of the parent figure, as documented in the help file for the "axes" command (doc axes). I don't know how that will affect the order of the figure's 'Children' property though.
Greg (view profile)
As Kris Thielemans points out, if you specify a Y offset without specifying an X offset, the value will be applied to the title's X offset. The user can circumvent the bug by specifying a 0 offset for x in the command call. The bug can be fixed in the code by moving line 155 ("io=io+1;") in the "get_off" function to before the if statement (say to a new line 154).
Rafa Valero (view profile)
Thanks, It works really well.
Kris Thielemans (view profile)
works nicely.
Only problem I see is with handling of the offset options. For example,
mtit('text','yoff',.2)
actually gives an xoffset. Seems you have to specify x,y offset in order.
Andres (view profile)
To those who are asking about a second line in the title, or making just more space for it, that's easy, just use sprintf inside mtit, like this:
mtit(sprintf('LINE 1 \n LINE 2\n\n\n'))
By the way, I haven't used all the options, but at least for the basic stuff (title for a 2x2 figure) it works very well.
n (view profile)
Hi,
Can you please update it for a title input as a cell, where we can define more than a single line title as well?
Thanks
Phil (view profile)
yuvaraj (view profile)
Its working fine
yuvaraj (view profile)
mtit ('Vz=25', 'FontWeight','bold');
when use this command to have a title for my subplots
It displays an error like the one shown below
??? Undefined function or method 'mtit' for input arguments of type 'char'.
Vahid (view profile)
works nicely!
Lakshmi Kolluru (view profile)
its really nice and helped me do what i wanted.
Yoichi (view profile)
Maikol Solís Chacón (view profile)
Heinri Brink (view profile)
Ok, but this does not work for a two line title. I want to add a title with two lines as in title({Line1,Line2});
Joshua Kaizer (view profile)
works very well
Roland Pasto (view profile)
David (view profile)
A simple, handy function - thank you!
However, I had trouble with the 'xoff', 'yoff', etc. options. When specifying just one of these, the title moved horizontally no matter which of these offsets was entered. I exchanged lines 154 and 155 in the code:
io=io+1;
if any(ix)
and now the offsets work individually or together.
Pawel S (view profile)
Very easy to handle. It did exaclty what I wanted. Thx!
Adam A (view profile)
Does the job nicely, thanks.
shlomix (view profile)
us (view profile)
this happens by design:
after MTIT terminates, the current (active) axis (GCA) is the handle of the invisible surrounding axis created by MTIT...
i've changed this behavior and an update should show up soon...
in the meantime, you can use this (tedious) approach
% create your figure/axes
cah=gca; % <- save current axis handle
mtit(gcf,'foo');
axes(cah); % <- reset current axis handle
us
sophie neve (view profile)
I got a problem with it... makes the rotation of 3D surf impossible....
Nice but to be really good the rest of the plot needs to be moved to create space for the title
Great work, good to have it.
This is one I have been looking. It is very useful. Thanks.
nice one, just what i was looking for