multiple y axis plot (plotyy)

1,199 views
Skip to first unread message

5050Vision

unread,
Oct 11, 2011, 2:51:17 PM10/11/11
to freemat
Hi,

Is there a function for plotting on multiple y axis in the same
plot? In Matlab the function is plotyy.

5050Vision

jonw0224

unread,
Oct 17, 2011, 12:04:54 PM10/17/11
to freemat
5050vision,

Try this:

%Create something to plot
x = linspace(0,10);
y1 = x;
y2 = 10 - x;

%Plot it
plot(x,y1,x,y2);

%Create the second axis
h1 = axes('yaxislocation', 'right');
axes(h1);

%I'm not sure why I have to plot it again to get the second axis to
show up...
hold on;
plot(x,y1, x, y2);

-Jonathan

aggie

unread,
Aug 20, 2012, 11:03:43 PM8/20/12
to fre...@googlegroups.com
Is there anyway to plot 3 or more y-axis?

Jonathan Weaver

unread,
Sep 7, 2012, 9:34:34 AM9/7/12
to fre...@googlegroups.com
I've played around with it, looked through some documentation, and this is the best I can do:

% Create variable to plot

x = linspace(0,10);
y1 = x;

y2 = x.^2;
y3 = x.^3;

% Plot first function on first axis

ax1 = gca;
l1 = line(x,y1);
set(ax1,'Color','none'); % Set background transparent

% Plot second function on second axis

ax2 = axes('YAxisLocation','right');
l2 = line(x,y2);
set(ax2,'YColor','b'); % Set axis and line to blue
set(l2,'color','b');
set(ax2,'Color','none'); % Set background transparent

% Plot third function on third axis

ax3 = axes;
l3 = line(x,y3); % Set axis and line to red
set(l3,'color','r');
set(ax3,'YColor','r');


What I can't figure out is how to stack the x axis labels nicely so they don't overlap.  Maybe someone else can build on this.

Reply all
Reply to author
Forward
0 new messages