Code covered by the BSD License  

Highlights from
addtxaxis

4.08333

4.1 | 12 ratings Rate this file 34 Downloads (last 30 days) File Size: 3.09 KB File ID: #4036
image thumbnail

addtxaxis

by Francois Bouffard

 

03 Oct 2003 (Updated 11 Oct 2004)

Adds a top x-axis with arbitrary scale

| Watch this File

File Information
Description

This function adds a second dummy x-axis on the top of a given axes object. This dummy x-axis has (internally) the same scaling (linear or log) than the main x-axis, but is used to display ticks and tick labels which are on a transformed scale.

The transformation is arbitrary, but the transformed axis cannot be used to create plots with transformed x coordinates. The given transformation is in fact the inverse transform, that is, the transform used to go from the secondary axis to the original axis (e.g. displaying a log scale would be done by providing a transform '10.^x').

The transformed axis can be removed cleanly by issuing a simple command.

Typical uses of addtxaxis would include displaying a secondary x-axis following reciprocal or logarithmic scales (e.g. frequency and wavelength on the same plot).

Acknowledgements
This submission has inspired the following:
Add top X-axis with different scale
MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
21 Oct 2003 Jakob van Bethlehem

doesn't work for some reason

21 Oct 2003 Jakob van Bethlehem

I have to change my previous entry. I did work very nice. I didn't really understand the error message I got in the beginning but when this changed I got the script working. So what was the problem. I got a variable c defined in my workspace. I wanted a transformation 'log10(c)-x', but the script didn't recognize this c. In my case c was a single constant so I could just calculate the value of log10(c) and put that in the string. That worked, but this might give problems for others if c is an array instead of a number. I don't really understand why the c was not recognized. I mean: the Matlab functions don't give problems. This does need improvement however.

22 Oct 2003 François Bouffard

A fix was submitted on 2003-10-22 so that the expression of the transform is now evaluated in the base workspace, thus enabling the use of variables defined there.

10 Jun 2004 François Bouffard

Sorry for any inconvenience; the fix was not correctly submitted on 2003-10-22, and was resubmitted on 2004-06-09. The current version now really fixes J. van Bethlehem's problem.

11 Jun 2004 kris zacny

Program works very well. I also received a lot of help from François explaining how the program works and how to plot my specific data sets. He did a real good job explaining and trying to understand my needs. Thank you so much!

Kris

11 Nov 2004 John Lipp

Great little chunk of code. Adding a second x axis is not easy, but this makes it a far more manageable task!
Would score 5 in my opinion if it could auto determine the ticks...

20 Apr 2005 Markus Loecher

Very nice utility. I wished for two things:
 - an option to have the tick and axis labels (of the new top axis) face inward and maybe even place the axis label to the right instead of center (so they won't interfere with the title)
- a simple example of usage.

25 Apr 2006 Carlos Baiz

This is what I was looking for. Thanks.

22 Mar 2007 Tom Allison

Thank you so much. Saved me hours.

21 Aug 2007 Saeed Tahvili

Very Good, thanks...
I was looking for that as well.
A simple example would be really helpful.

13 Sep 2007 Amol Singh

This was a really nice program. I was autoamting a plotting process and wanted reciprocal axis at the top of x axis. Although i modified program to write a multiplied value ie instead of 0.2 i wanted it to be 200.
good work indeed...

15 Nov 2007 Hai Dinh

Dear François Bouffard:

Are there any way to add the top x-axis that is has a one-to-one relationship to the bottom main x-axis? (not linear nor log scale as explained in your program)

Thanks,
Hai Dinh

15 Nov 2007 François Bouffard

In reply to Hai Dinh: using addtxaxis, you can simply provide 'x' as the transform. However the ticks argument is also mandatory, so that you will have to provide a vector of tick positions as well. Maybe using plotxx by Denis Gilbert (also available on MatlabCentral's FileExchange) would be easier for you.

11 May 2008 AHMET ANIL DINDAR

Thanks, what I was looking for.

10 Oct 2008 Natalia Gomez

Exactly what I needed!

04 Aug 2011 Stephen

I love the idea of this program but François can you please give an example of usage because it is not really clear what you mean by providing a vector of ticks. Can it just be the ticks I want to show up on that axis? (ie v=[1 2 3 4] ?)

Please login to add a comment or rating.
Updates
23 Oct 2003

Fix of bug found by Jakob van Bethlehem (whom I whish to thank): the transform is now evaluated in the base workspace, so that variables defined there can be used in the expression of the transformation.

10 Jun 2004

It seems the last fix was incorrectly transmitted. This is a retry.

11 Oct 2004

Fixes suggested by Lars Kappei: Box propery is now "Off" and correct units are used in transformed axis.

Tag Activity for this File
Tag Applied By Date/Time
annotation Francois Bouffard 22 Oct 2008 07:08:20
customization Francois Bouffard 22 Oct 2008 07:08:20
double Francois Bouffard 22 Oct 2008 07:08:20
xaxis Francois Bouffard 22 Oct 2008 07:08:20
transformation Francois Bouffard 22 Oct 2008 07:08:20
graphics Francois Bouffard 22 Oct 2008 07:08:20

Contact us at files@mathworks.com