AddSecondAxis

Addsecondaxis is a simple function which adds a second abscissae or ordinate on an existing plot.
389 Downloads
Updated 31 Oct 2012

View License

Addsecondaxis(Lim,h,axpos,vecticks)

Addsecondaxis is a simple function which adds a second abscissae or ordinate on an existing
plot. Unlike plotxx or plotyy it does not plot a new curve. Addsecond axis is usefull if one wants to see the same curve as a function of 2 different absissae or ordinates. For instance a time serie as a function of
%an axis in hours and asecond axis in days
usage:
Addsecondaxis(Lim) uses the vector Lim to define a second horizontal axis absissae at the top of the current plot. if Lim has two elements. Lim(1) and Lim(2) are used
for the limits of the second axis. If Lim has more than 2 elements
min(Lim) and max(Lim) are used for the limits of the second axis

Addsecondaxis(Lim,h) where h is an axis handle add the second axis horizontal axis coordinates at the top of axes(h)

Addsecondaxis(Lim,h,axpos) where axpos is a string either equal to %'x' or 'y' adds either a second absissae or ordinate
on the second axis

Addsecondaxis(Lim,h,axpos,vecticks) uses the vector vectick to define the
ticks on the second axis

Examples
t=0:1:5*24*60; %time in mn
y=t; figure; plot(t,y);
Addsecondaxis(t/(24*60)) %add as second x axis in days at the top;
the previous command is equivalent to
figure; plot(t,y);
Addsecondaxis([0 5])
to fix the ticks every 1 day
figure; plot(t,y);
Addsecondaxis([0 5],[],[],[0:1:5])
if on want a second ordinate axis normalised by A
A=5;
figure; plot(t,y);
Addsecondaxis(y/A,[],'y')

Cite As

Yannis Cuypers (2026). AddSecondAxis (https://www.mathworks.com/matlabcentral/fileexchange/38852-addsecondaxis), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Two y-axis in Help Center and MATLAB Answers
Version Published Release Notes
1.0.0.0