13 Downloads
Updated 29 Mar 2005
No License
Features:
* Automatically sets xlim to the same for all subplots Removes xticklabels where it is not needed.
* Can join a subplots (if it is made with subplot instead of subaxis)
* Can set the ylabel position to the same for all subplots
* Can almost allways avoid that the yticklabels are written on top of each other
* Can automatically add a),b),c) to each subplot
----------
% helper function to clean up subplots that have common x axises
USAGE: samexaxis([optionalarguments])
Optional arguments:
* YAxisLocation (default='left') : choose left,right, alternate or alternate2
* XAxisLocation (default='bottom') : choose bottom,top or both
* YLabelDistance (default=1.4)
* Box (default='on')
* XTick
* XTickLabel
* XMinorTick
* ABC : add a),b),c), ... to each sub plot
* Join: joins the subplots vertically
* YTickAntiClash: try to aviod yticklabel clashes (default=false)
Example:
subplot(3,1,1);
plot(randn(100,1),randn(100,1),'x');
ylabel('QF')
subplot(3,1,2);
plot(randn(100,1),randn(100,1)*10,'x');
ylabel('HT');
subplot(3,1,3);
plot(randn(100,1),randn(100,1)*33,'x');
ylabel('DV');
samexaxis('abc','xmt','on','ytac','join','yld',1)
Aslak Grinsted (2021). samexaxis (nice subplots with same x axis) (https://www.mathworks.com/matlabcentral/fileexchange/7169-samexaxis-nice-subplots-with-same-x-axis), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
Works fine, but needs another function which is parseArgs.m.
I think the so many options made it a bit complex than it should...
This function needs updating.... it does not work!!!! Even when using the provided example....
please how to realizethe same thing with axis y?
I am not able to use this it says error in 33
thx for the function!!
I recommend subtightplot fucntion by Felipe G. Nievinski too.
Great function!!. How can I change the font size of a) -> b) -> c)? Thank you very much
Does not work when one of the subplots is 'yyplot'. The plot with the second y-axis disappears
@Lokesh: As Yohai suggested, also download this file and then your problem should be solved: http://www.mathworks.com/matlabcentral/fileexchange/3448-parse-function-arguments
this is not working .... it says error in line 33.
how can I make single ylable instead of two or three??
for refrence please see figure 5 on
http://pubs.acs.org/doi/pdf/10.1021/ja405844j
how can I make single ylable instead of two or three??
for refrence please see figure 5 on
http://pubs.acs.org/doi/pdf/10.1021/ja405844j
Very useful function. One minor issue: When subplots' y axis limits are explicitly set, it tends to result in yticklabel clashes. For example,
subplot(211)
plot(randn(1,100));
set(gca,'YLim',[-3 3]);
subplot(212)
plot(randn(1,100));
set(gca,'YLim',[-4 4]);
samexaxis('xmt','off','ytac','yld',1,'box','on','join')
Thx, still working great!
great work!
I have exactly the same problem as Kuo-Hsien. Can anybody recommend a solution? Other than that, great work!
yes. Download it from
http://www.mathworks.com/matlabcentral/fileexchange/3448-parse-function-arguments
I tried to use this in 7.12.0 and parseArgs does not exist. Is there a trivial work aroung?
very nice.
it is a pity though that it cannot be used with plotyy
This is great! However, I would like to plot 18 subplots (6 rows, 3 cols). I would like to join the 6 subplots in each column and have a total of 3 x-axis (one per column). I have downloaded subaxis and this works with your example however I can't get this working on my data.
I think this is a nice code, but I would like to plot two y axis in each panel, I used plotyy first, then use this code, but seems not work.
Hi Aslak, can you let me know how to how "abc" result as (a)-->(b)-->(c)-->(d)-->(e)-->(f) not (b)-->(a)-->(d)-->(c)-->(f)-->(e)
Please see this code:
subaxis(1,2,3,'sv',0,'sh',0.1)
spacing=10%
plot(1:6,randn(6,1))
for ii=2:6
subaxis(ii)
with
plot(1:6,randn(6,1))
end
samexaxis('abc','ytac')
set(subaxis(5),'xticklabelmode','auto')
set(subaxis(6),'xticklabelmode','auto')
Thanks.
I was able to take the xlims and adjust that section of code to work for my program and fix the limits on the y axis I needed, Thanks.
Really nice function.
Produces really neat plots
To resolve the error seen in Ramis' statement, download the parseArgs.m and Subaxi.m files at the following link:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3696&objectType=file
After that, the sameaxis functions works perfectly. I found it very useful and well written.
I downloaded parseArgs as well, but got the following error for the example of the author:
??? Function 'fieldnames' is not defined for values of class 'cell'.
Error in ==> parseargs at 35
fields = fieldnames(X);
Error in ==> samexaxis at 33
Args=parseArgs(varargin,Args,{'abc' 'join' 'ytickanticlash'});
Needs the parseArgs routine downloadable here.
The example worked as expected. I also downloaded subaxis, and am wondering if you can provide an example like Carles asked for: a 3 x 2 tiled plot using sameaxis and subaxis? that would be very helpful. Thanks!
I am running the author's sample with the 4/14/05 update of samexaxis and Matlab 7.0.4, but get an error:
??? Undefined command/function 'parseArgs'.
Error in ==> samexaxis at 33
Args=parseArgs(varargin,Args,{'abc' 'join' 'ytickanticlash'});
Error in ==> test at 4
samexaxis('abc','xmt','on','ytac','join','yld',1)
An extremely useful function, I wish it worked :(
Carlos try this: (download subaxis)
subaxis(3,2,1,'sv',0,'sh',0.1) %vertical spacing = zero, horizontal spacing=10%
plot(1:6,randn(6,1))
for ii=2:6
subaxis(ii) %it remembers the settings you made the first subplot with
plot(1:6,randn(6,1))
end
samexaxis('ytac')
set(subaxis(5),'xticklabelmode','auto') %samexaxis might turn ticks off ...
set(subaxis(6),'xticklabelmode','auto')
hello
Excellent job!
Nevertheless, i am having an error when i am trying to do it for 6 subplots (3 rows, 2 cols). I would like to get 2 x axis (one per col) and join the 3 subplots that each col has got. is that possible?
Aslak, would it be possible, by any chance, to see an R13 version of your function, for poor souls not yet having Matlab 7?
I think the error is caused by you having a nonstandard version of sort.m on your path.
Unfortunately,it is exactly what I was looking for. But I need some help. I'm not able to run the example. I obtained this error.
??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.
Error in ==> ismember at 110
[s,idx] = sort(s(:));
Please rate this... It would be nice to receive some encouragement to keep submitting useful bits on matlabcentral.