File Exchange

image thumbnail


version (2.04 KB) by Denis Gilbert
PLOTXX Create graphs with x axes on both top and bottom


Updated 19 Feb 2002

View License

PLOTXX Create graphs with x axes on both top and bottom

Similar to PLOTYY, but ... the independent variable is on the y-axis, and both dependent variables are on the x-axis.

For example, you may wish to plot temperature and salinity as a function of depth in the ocean. In the atmosphere, plot temperature and relative humidity as a function of altitude, etc.

Cite As

Denis Gilbert (2020). plotxx.m (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (27)

Maria M.

does not work for multiple plots

Thanks!! Working great!


Finally! A subroutine that did exactly what I wanted right away. Thank you!

yuanyuan gu

Thank you very much!!

Jorge Otero

Just what I was looking for !


Sam Lo

Try to do this with pcolor plot with one of the x-axis being an inverse of the other x-axis times some constant. Can't seem to get it to work.

Can someone help me??I´m trying to use this rotine with subplot, but I can´t do this and I saw another comments about this!Thank you


very useful but sloppy code...
Could have done better...
Yet very useful

% This works at least:

set(findobj('Type','line'), 'LineWidth',lw)

% From web('jar:file:///C:/Program Files/MATLAB/R2009b/help/techdoc/help.jar!/ref/set.html', '-helpbrowser')


Is it possible to make a bar graph and a line graph with different x axes on the same figure using this program? Thanks.

Simon Vassant

Good stuff. How can I make it work for inversely proportionnal axes : i.e. wavelength (in microns) and wavenumbers (in cm^-1) ?

Guyennon Nicolas

thanks a lot for this solution ! (very usefull for vertical profiles)

set(ax(1),'XLim',[min(x1) max(x1)]);
set(ax(2),'XLim',[min(x2) max(x2)]);

to get autoscale on both x axis

or you may prefer to use :
[low,high,ticks] = bestscale(ylim1(1),ylim1(2),ylim2(1),ylim2(2),islog1 | islog2);
set(ax(1),'XLim',[low(1) high(1)],'XTick',xticks1);
set(ax(2),'XLim',[low(2) high(2)],'XTick',xticks2);

if you want to get a better ticks layout

(see open plotyy to copy bestscale sub function)

abdur rahman

very useful thanks

Leo B

to get the position right
set(ax(2),'YAxisLocation','right','Color','none', ...

Dave Sproson

To use with subplot, you need to comment out

set(ax(1),'Position',[0.12 0.12 0.75 0.70])

on line 65.

James Housley

Is it just me, or does this not work with subplots?

Peter Burns

To avoid inconsistent axes ranges, I suggest calling
> axis tight
after plotxx. You might consider adding this to the function as a precausion.

Sloane Wiktorowicz

Useful as a corollary to plotyy. Would be useful to have two inversely proportional axes for one plot (e.g., wavelength on bottom and energy on top). Though this isn't too hard to do from plotxx. Thanks!

Sacit Cetiner

Thanks, saved me a lot of programming

Izru Garner

Well done Dennis by your scripts, I agree with Lina Chang.

yang ying

useful programme

Sachin Chandra

Very useful. I often why mathworks didnt have a function similar to plotyy..
I think additional parameters like passing colors,line width can be helpful too..

Lina Chang

Very helpful for creating nomographs. Thanks.


Two new input arguments have been added to ease the task of labeling the axes.

modifying description

MATLAB Release Compatibility
Created with R10
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags