AddSecondAxis
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
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Graphics > 2-D and 3-D Plots > Line Plots > Two y-axis >
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 |
