File Exchange

image thumbnail

addaxis_unit

version 1.6 (12.3 KB) by

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

0 Downloads

Updated

View License

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.

Comments and Ratings (10)

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.

christhechris

does kill data cursor, but otherwise works great.

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

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.

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

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

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

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

Claudio Gelmi

Claudio Gelmi (view profile)

What is the difference with plotyy?

Updates

1.6

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

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.

1.4

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

1.3

updated description

1.2

added support for subplots

1.1

updated the description

MATLAB Release
MATLAB 7.5 (R2007b)

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

» Watch video