Noah
Noah

Reputation: 361

How do I plot more than two functions onto the same graph with very different ranges in Octave?

I can't find any info on how to do this on the Internet other than to use plotyy which only seems to work for two functions.

Upvotes: 0

Views: 1061

Answers (2)

Tasos Papastylianou
Tasos Papastylianou

Reputation: 22215

In my opinion, the way to do this that confers the most manual control is to create three overlapping axes with the plots you need, and only display the axis for the topmost one. You could even create 'empty' axes just so you they can serve as the only axis with defined 'limits' in the x and y axes.

Example:

ax1 = axes();
X1 = linspace(0,8*pi, 100);   Y1 = sin(X1);
plot(X1, Y1, 'r', 'linewidth', 10);

ax2 = axes();
h = ezplot(@(x) x .* sin(x), [-100, 100]); set(h, 'color', 'w');

ax3 = axes();
image()

%% place them on top of each other by calling them in the order you want
axes(ax3); % bottommost
axes(ax1);
axes(ax2); % topmost

set(ax1, 'visible', 'off');
set(ax2, 'visible', 'off');
set(ax3, 'visible', 'on');  % this is the axes who's limits will show

enter image description here

Upvotes: 1

Michael
Michael

Reputation: 5335

From Matlab documentation:

Use Right y-Axis for Two Data Sets

Plot three data sets using a graph with two y-axes. Plot one set of data associated with the left y-axis. Plot two sets of data associated with the right y-axis by using two-column matrices.

x = linspace(0,10);
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
y3 = 0.2*exp(-0.5*x).*sin(10*x);

plotyy(x,y1,[x',x'],[y2',y3']);

Upvotes: 2

Related Questions