File Exchange

image thumbnail


version (1.47 KB) by Laura Proctor
MULTIPLOTYYY allows the user to plot multiple lines on three sets of y-axes.


Updated 01 Sep 2016

View Version History

View License

MULTIPLOTYYY plots using three sets of y-axes values. Additionally, multiple lines can be plotted against each y-axis. Therefore, the inputs to the function must be grouped into cell arrays.
Here is an example call to the function:
x1 = (0:0.01:1)';
x2 = (0:0.1:1)';
x3 = (0:0.05:1)';
y1 = x1;
y2 = x2.^2;
y3 = x3.^3;
y4 = sin(x1);
y5 = fliplr(2*x1.^2);
y6 = 7*cos(x1);
y7 = 7*log(x1+1.2);
ylabels{1}='First y-label';
ylabels{2}='Second y-label';
ylabels{3}='Third y-label';
[ax,hlines] = multiplotyyy({x1,y1,x2,y2,x3,y3,x1,y4},{x1,y5},{x1,[y6,y7]},ylabels);legend(cat(1,hlines{:}),'a','b','c','d','e','f','g','location','w')

Cite As

Laura Proctor (2020). multiplotyyy (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (18)

Edgar Budde

It's wonderful but still, I need to explore more like
1. How to change second y-scale as log scale
2. how to customise line styles


It works really good. But all the files available here are having problem with data tips/cursor.

Julius Wanner

You can make an xalbel by adding xlabel(ax(1),'text') after the multiplotyyy function

Muhammad Luthfi

how can I make the xlabel in this example? Thank you


sola neil

When I use “ set(ax,'Xlim',[0.77 0.795]); ” to adjust the range of axi X,the third group lines can't zoom in.



I can't make the example work. Everytime, I have this error message :
"Structure assignment to non-structure object.
Error in multiplotyyy (line 59)
ax(1).YColor = 'b';"

Any idea of what should be done?




Thank you! How can I use this function when I want to plot e.g. two multiplotyyy plots in one window? I think subplot is not working with it. Can someone help me please?

Shiva Asapu

This is wonderful. Just what I was looking for.

Ainara Lopez

Great function Laura! Thank you very much. Really useful!

liangsai liang

Xavier Matabosch

Great function! I needed to plot Power and Thrust curves of a wind-turbine for a college work, and multiplotyyy worked perfectly.

Thank you very much! I'll make sure you appear on the acknowledgements.

Laura Proctor

Andreas, all the lines are saved in the output, hlines. You can change the style using these. Or, you can change it in the code. If you let me know what you're looking for, I can help out.

To work with the legend, you can use the following modifications after you call the code that will align the axes with a legend on the left hand side. Please feel free to contact me directly, I'd be happy to help!

>> leg = legend(cat(1,hlines{:}),'a','b','c','d','e','f','g','location','w');
>> leg.Location = 'westoutside';
>> ax(2).Position = ax(1).Position;
>> ax(3).Position = ax(1).Position;
>> offset = 0.7/5.5;
>> ax(3).Position(3) = ax(3).Position(3) + offset;
>> ax(3).XLim = [ ax(1).XLim(1) ax(1).XLim(2)*(1 + 1/(ax(1).Position(3)) * offset)];

Andreas Kaineder

Great tool!! Is there a way to change the linestyle?

The only problem is, that the 2nd & 3rd axis are messed up when I put the legend outside of the plot. Can anybody help me with this? When I plot multiple lines it's confusing with the legend inside the plot. Thanks!


when I run the example it shows me that: Undefined function 'multiplotyyy' for input arguments of type 'cell'
what is it wrong then? thanks!

Giacomo Alessandroni


Couple of mistakes in the example, but otherwise works as advertised, thanks!

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: plotyyy

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!