4.66667
4.7 | 9 ratings Rate this file 70 Downloads (last 30 days) File Size: 3.29 KB File ID: #9046 Version: 1.0
image thumbnail

Add top X-axis with different scale

by

 

15 Nov 2005 (Updated )

Add an X-axis on top (additional to the one on bottom) of the figure, with its own ticks labels ...

| Watch this File

File Information
Description

Add an X-axis on top (additional to the one on bottom) of the figure, with its own ticks labels and axis label (allow double scale).
Ticks, minor ticks positions and x limits are set to be identical for top and bottom axis. Moreover, they are linked, i.e. a modification of one of them, even after execution of this function, will result in modification of the other one.

Acknowledgements

Addtxaxis inspired this file.

This file inspired Link Top Axis Data.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
30 Jun 2014 p kung

p kung (view profile)

 
29 Nov 2012 Chern Hui Lee  
07 Sep 2012 Sushovan  
23 Jul 2012 Paul

Paul (view profile)

Very useful! Thanks a lot.

03 Mar 2012 Massimo Ciacci

Massimo Ciacci (view profile)

After checking other solutions out there, this is by far the best and simple too, without complicate callback mechanisms to regenerate the labels on the secondary axis, which still zooms properly.

I had tried

set(gca, 'XTickMode', 'auto', 'XTickLabelMode', 'auto')

in the hope that labels would be updated automatically, but as a result the secondary axis becomes identical to the first!

Workaround, use manual xticks to start with, dense enough, before calling the function. But at least the new axis zooms properly! Well done Emmanuel!

03 Mar 2012 Massimo Ciacci

Massimo Ciacci (view profile)

It's a pity that after the second axis is drawn the xticklabels are frozen, so if one zooms in, new labels are not generated...

Comment only
10 Nov 2009 Chiao

Chiao (view profile)

 
06 Aug 2009 Itamar

Itamar (view profile)

Hi,
First, thank you for your submission. Well documanted and written. It took me some time to figure it out, but it works like magic and as in the example.
You had really helped me here.
Thanks

19 Feb 2009 Pacome Delva

the script doesn't work for a loglog plot...

Comment only
19 Feb 2009 Pacome Delva

Hello, thank you for your contribution.
I have a problem. I want to add a top log axis to a loglog plot. My problem is that I don't know how to obtain a nice formatting, with the power in super script, as for the down x axis. I have only access to the fprinf option for the formatting.
Thank you

21 Nov 2008 Lars Olav Vestland

I agree with YI xu. (Somehow I cannot make it to function, has the evalin function been changed in MATLAB?)

Stian: axec() function? Did you mistype? Does not seem to be in MATLAB nor in 'fileexchange'.

Comment only
07 Feb 2007 YI xu

For a general user, I wonder if somebody can give an example statement, it's easier for users to understand. Thanks

Comment only
28 Dec 2005 Stian Ingebrigtsen

Why bother to use two manipulated Subplots when you can use the axec( ) function to generate a new set of opposite axis on your graph??? Your code will be a lot simpler and it is still possible to link axis properties...

Comment only
29 Nov 2005 Emmanuel Dinnat

Reply to John D'Errico
1st, thank you for the return.
The change has been done in the new version.
Also changed the way of evaluating the 'expression'. That should allow more complexe and easier implementation of these 'expressions'.

Comment only
18 Nov 2005 John D'Errico

I don't forsee a need a secondary x-axis much, but when I
want one, this is a good, simple tool for that purpose.

My only (minor) beef is with the property/value pair
interface. Its nice if properties can be shortened, as long as that shortening is unambiguous. Thus, the 'expression'
property should be properly used even if we supplied its
name as 'exp'. Since this takes only a couple of lines of
code to implement, its a very nice feature.

Updates
28 Nov 2005

Now evaluates expression in the 'base' workspace (allow for more complex expressions), use case insensitive and simplified property names.

Contact us