Code covered by the BSD License  

Highlights from
addaxis_unit

4.0

4.0 | 5 ratings Rate this file 16 Downloads (last 30 days) File Size: 12.3 KB File ID: #26928
image thumbnail

addaxis_unit

by

 

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
Description

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 (9)
19 Aug 2014 Chris Betters

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.

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:

set(hAxes(2),'yticklabel',num2str(ticks2unit,'%4.2f'))

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
set(HAXES(i+1),'yticklabel',num2str(ticks2unit),'%4.2f')

??? Error while evaluating figure ResizeFcn

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

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.

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.

14 Mar 2010 Claudio Gelmi

What is the difference with plotyy?

Updates
15 Mar 2010

updated the description

16 Mar 2010

added support for subplots

16 Mar 2010

updated description

17 Mar 2010

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

19 Mar 2010

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

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

Contact us