4.53333

4.5 | 15 ratings Rate this file 72 downloads (last 30 days) File Size: 20.63 KB File ID: #9016

addaxis

by Harry Lee

 

12 Nov 2005 (Updated 21 Feb 2006)

Code covered by BSD License  

Add multiple y-axes to plots. zoomable with zoom modification.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

Download Now | Watch this File

File Information
Description

Adds multiple axes to plots using addaxis.m. Automatically adjusts axes to accomodate as many axes as you want.

Add more plots to any added axes with addaxisplot.m

Add y-labels to any of the axes with addaxislabels.m

All plots zoom together. A small modification to the zoom function allows all of the added axes to update with zoom.

zoom modifications for R11.1 and R14SP2 are included.

Usage is almost exactly like the plot command, see the help for addaxis.m for examples.

Acknowledgements
This submission has inspired the following:
addaxes.m v1.1 (Sep 2009)
MATLAB release MATLAB 5.3.1 (R11.1)
Zip File Content  
Other Files
zoom_R11.1_.m,
zoom_R14SP2_.m,
Readme.txt,
aa_splot.m,
addaxis.m,
addaxislabel.m,
addaxisplot.m,
addaxisreset.m,
addaxisset.m,
buttonupfcn2D_R14SP2_.m,
getaddaxisdata.m,
setaddaxisdata.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (19)
25 Nov 2005 Johannes Korsawe

A really superb tool. Just what i was about to write on my own. Thank you!

I would just allow the user to choose the color of subsequent plots to the same additional axis (addaxisplot line 43) and not force them to be the same color as the axis.

17 Jan 2006 Andrey Loginov

A nice tool thank you,
It is better not redefine splot.m which is used for plotting freq and time resp of system SYS,
Just rename to say splot__.m and use

27 Apr 2006 Neelu D

Best among the posted on the website for adding secondary axis or zooming.

14 Aug 2006 A Pohlmann

I wanted to plot several curves and then add another one on a second y-axis. Tried plotyy and a few different tools and finally used this. Works ok if you don't mess with the orignal axis after adding the second. However, like some other tools it affects the size of subplots with some of them being slimmer or flatter, at random, which means you need to resize manually. Also the second axis is shifted slightly upwards. Other tools seemed to have similar problems, so I wonder whether that has some other cause (thus 4*). Using Matlab 7.0.4 on X11. Nevertheless I get usable graphs.

15 Dec 2006 fabiano busdraghi

nice tool. it is too shame that you can not add x axis, that is what i'm looking for
fabiano

08 Feb 2007 Patrick Celka

Best to fix the plotyy bug

07 Jul 2007 beckali abdel

useful, thanks

26 Jul 2007 Ian Howat

Great tool. Much^10 easier to use than plotyy. I agree with fabiano that a good modification would be to add multiple horizontal labels.

16 Aug 2007 Xianyu Zhao

Very useful, thanks a lot

20 Nov 2007 Wang Ding

a very useful tool! Thanks a lot

14 Mar 2008 R Meyer

I think this is a very useful tool, but I guess I have some problems, because there are always error messages when I am using the zoom function. Perhaps it is because I am using the new version of MatLab but I do not know exactly because I have got the software since only a few days. Perhaps anybody can help me.

18 Aug 2008 Amir Abbas Zadpoor

Well done! Thanks a lot

02 Sep 2008 R. J

Hi. This is a great tool, I used it to create something more specific for my needs, so thank you for the ideas. I'm wondering if anyone has figured out a fix to a legend..I can only add to the legend the number of entries on the left side.

01 Jul 2009 Ian

Hi, good tool.
Is it possible to make some of the additional axis use a log scale?

30 Jul 2009 Andres

A good multiple y-axis tool - it could be a bit more customizable. Use linkzoom ( http://www.mathworks.com/matlabcentral/fileexchange/21414 ) to avoid the zoom modification, or use Carlos Adrian's derivative (not tested yet).

07 Aug 2009 Ibrahim M

Great work!

Ibrahim M.

18 Aug 2009 John

Great Tool. Would be great if you could update the zoom functionality to more recent versions of MATLAB.

18 Aug 2009 John  
22 Nov 2009 Ben

Great tool! I'm surprised matlab doesn't handle this better natively (the way gnuplot does).

If you need to change linestyles, ytics, etc, just change the declaration of addaxis to:

function [hplts,h_ax] = addaxis(varargin)

This give you back the handle to the plot (as if you called h=plot(...)) and the axes (h=axes(...)) yourself.

The only outstanding issue I have is positioning a legend outside the plot...one solution might be to put all the new y-axes on the right (instead of alternating left/right), and then legend Location NorthEast, but I haven't tried that yet.

Please login to add a comment or rating.
Updates
16 Nov 2005

Removed debugging line in zoom.m that was displaying axis limits.

28 Nov 2005

Added support for R14SP2

29 Nov 2005

In response to suggestion, addaxisplot only changes color to match axis if no color is specified.

27 Dec 2005

*Added feature to allow setting y-limits after plotting.
*Added feature to allow removal of all added axes.
*Improved implementation to avoid using 'userdata'.

15 Feb 2006

changed splot.m to aa_splot.m in response to a user's suggestion.

21 Feb 2006

Fixed small bug in addaxisplot so it works to add plots to the original axis, also addaxislabel input made more flexible.

Tag Activity for this File
Tag Applied By Date/Time
specialized Harry Lee 22 Oct 2008 08:06:07
plotting Harry Lee 22 Oct 2008 08:06:07
plotyy Harry Lee 22 Oct 2008 08:06:07
multiple Harry Lee 22 Oct 2008 08:06:07
yaxis Harry Lee 22 Oct 2008 08:06:07
add axis Harry Lee 22 Oct 2008 08:06:07
zoom Harry Lee 22 Oct 2008 08:06:07
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com