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.
Thank you very much
Can you give an examle I can not make it work with pcolor plot .
Very useful!!! I only can set the axes labels by manual location of them.
and this error:
One or more output arguments not assigned during call to "evalin".
Error in ==> addTopXAxis at 132
set(nAxis, 'xtickLabel', num2str(evalin('base',
Can anyone help me?
I have found the solution - to plot everything in the old axes
thank you for the useful function!
Could someone please give a short example how to connect an additional graph to the new horizontal axis?
creates a line directly on the new horizontal axis
Very useful! Thanks a lot.
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!
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...
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.
the script doesn't work for a loglog plot...
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.
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'.
For a general user, I wonder if somebody can give an example statement, it's easier for users to understand. Thanks
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...
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'.
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.
Now evaluates expression in the 'base' workspace (allow for more complex expressions), use case insensitive and simplified property names.