View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.2 | 6 ratings Rate this file 8 Downloads (last 30 days) File Size: 12.3 KB File ID: #26928 Version: 1.6
image thumbnail




12 Mar 2010 (Updated )

This function adds a second y-axis to a x-y plot using a relationship between the two y-axes.

| Watch this File

File Information

This function allows to use two different y-axes with the same data in one plot. Note, that only one curve but in two different units is shown. This is the difference to plotyy which plots two different datasets into one figure.

Take a look to the screenshot and run the different examples in the zip-file to understand the usage.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
09 Apr 2015 Georgijs Bakradze

Thank you for the useful script! Is it possible to control the position of the the second y-axis label, and move it closer to the y-axis? Its position changes each time the numbers on the axis change.

19 Aug 2014 christhechris

does kill data cursor, but otherwise works great.

09 Aug 2010 Brad Stiritz

Hi Friedhelm, thanks for all the function updates. I really appreciate your responsiveness & openness. I wanted to let you know about a new possible issue. After the chart is rendered, the user should be able to select a plotted point & add an annotation using the Data Cursor tool, right? This isn't working for me after I run the addaxis_unit function. Could you please take a look? Thanks, Brad

02 Jun 2010 Friedhelm Steinhilber

Answer to Brad Stiritz: Thanks for this remark. In the newest version (date 2/6/2010), the string format of the ticks for the second y-axis can be controlled by using the optional fifth argument when calling the function addaxis_unit.

Comment only
31 May 2010 Brad Stiritz

Hi Friedhelm, thank you for updating the function per my previous request. I was hoping to be able to control the string formatting when the 'y1' ticks2unit option is specified. It appears that the formatting could be specified by modifying the num2str() calls in lines 146 & 175, a la:


This hack works as long as the figure is *not* resized. For some reason, my modification fails during resizing with the error:

??? Error using ==> set
Invalid parameter/value pair arguments

Error in ==> addaxis_unit>addaxis_unit_resizefcn at 175

??? Error while evaluating figure ResizeFcn

Any help or suggestions appreciated. Thank you again. ~Brad

Comment only
17 Mar 2010 Friedhelm Steinhilber

Answer to Brad Stirlitz: I updated the function, allowing to use the same ticks as on the first y-axis.

Comment only
16 Mar 2010 Brad Stiritz

Hi Friedhelm, great idea for a utility function! I have a slightly different use-case than the example you provided. In my case, I would like to have different units on the right-side axis, but I would like the right-side axis ticks to match up exactly with the left-side axis ticks. For example, let's say my left-axis tick labels are the values (1:10) and I would like to see what the log of those values are on the opposite axis. Would it be possible to achieve this using your function? Thanks, Brad

16 Mar 2010 Andre Guy Tranquille

15 Mar 2010 Friedhelm Steinhilber

Answer to Claudio Gelmi: plotyy plots two datasets into one figure. This function here plots one dataset with two different units.

Comment only
14 Mar 2010 Claudio Gelmi

Claudio Gelmi (view profile)

What is the difference with plotyy?

15 Mar 2010 1.1

updated the description

16 Mar 2010 1.2

added support for subplots

16 Mar 2010 1.3

updated description

17 Mar 2010 1.4

Now allows to use the same ticks as first y-axis. This is asked for by Brad Stiritz (16/03/2010).

19 Mar 2010 1.5

If second y-axis uses the same ticks as the first y-axis, the labels are calculated every time the figure is resized.

02 Jun 2010 1.6

The string format of the ticks of the second y-axis can be adjusted.

Contact us