Reputation: 25
I'm working with GUI in Octave to plot three Y Axis and one X Axis.
My Problem is that one Plot hides another plot. Acutually it should have to show every graph. But it shows only the last one of my codes. I used hold on
and hold off
codes to show multiple y graphs. But it doesn't work like this e.
My code for plotting looks like this.
h1 = axes ('position', [0.45 0.25 0.5 0.5], 'tag', 'plotarea','ycolor','r');
plot( h1, XData, YData, 'tag', 'plotobject','color','r');
hold on
h2 = axes ('position', [0.45 0.25 0.5 0.5], 'tag', 'plotarea_1','ycolor','b');
plot( h2, XData, Y_1Data, 'tag', 'plotobject_1','color','b')
hold on
h3 = axes ('position', [0.45 0.25 0.5 0.5], 'tag', 'plotarea_2','ycolor','k');
plot( h3, XData, Y_2Data, 'tag', 'plotobject_2','k');
hold off
grid on
endfunction
Any help appreciated, or tips on where to look.
Upvotes: 0
Views: 202
Reputation: 1296
For the axes after the first one, set the color
property to none
and nextplot
property to add
:
h1 = axes ('position', [0.45 0.25 0.5 0.5], 'tag', 'plotarea','ycolor','r');
plot( h1, XData, YData, 'tag', 'plotobject','color','r');
% either after creating the axes:
h2 = axes ('position', [0.45 0.25 0.5 0.5], 'tag', 'plotarea_1','ycolor','b', 'color', 'none');
set(gca, 'nextplot', 'add')
plot( h2, XData, Y_1Data, 'tag', 'plotobject_1','color','b')
% or while creating the axes:
h3 = axes ('position', [0.45 0.25 0.5 0.5], 'tag', 'plotarea_2','ycolor','k', ...
'color', 'none', 'nextplot', 'add');
plot( h3, XData, Y_2Data, 'tag', 'plotobject_2','k');
grid on
Upvotes: 1
Reputation: 1296
To explain the method in my comment:
x = 1:10;
y1 = [0.071787 0.713441 0.520276 0.983740 0.744507 0.595129 0.086762 0.228372 0.565195 0.308494];
y2 = y1 .^ 2;
y3 = y1 .* 2 - 1;
% normalize all data to range [0, 1]
y1off = y1 - min(y1);
y1nor = y1off / max(y1off);
y2off = y2 - min(y2);
y2nor = y2off / max(y2off);
y3off = y3 - (-1.2); % an arbitrary value
y3nor = y3off / (2.4); % this is like doing ylim([-1.2, -1.2 + 2.4])
plot(x, y1nor, 'r', x, y2nor, 'g', x, y3nor, 'b--');
nticks = 5;
yticks(linspace(0, 1, nticks));
yticklabels(arrayfun(@(a, b, c) sprintf('\\color{red}%6.2f \\color{green}%6.2f \\color{blue}%6.2f', a, b, c), ...
linspace(min(y1), max(y1), nticks), ...
linspace(min(y2), max(y2), nticks), ...
linspace(-1.2, -1.2 + 2.4, nticks), ...
'UniformOutput', false));
ylabel({'\color{red}Label 1', '\color{green}Label 2', '\color{blue}Label 3'})
This code results in this plot:
Upvotes: 2