0

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 picture.

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.

7
  • Dont make new axes. Each axes is creating a new axis (including the white squares) on top of each other. You want all your plots on the same axes! Commented Aug 11, 2021 at 11:35
  • Thanks for your answer @Ander Biguri! But in order to show three y axis at one time, I need to make new axes for that.... because my data has different units (mbar, µm and so one) I need to make another axis to show it at one time, like this Commented Aug 11, 2021 at 11:38
  • Ah, yes, but they cover each other. Not sure if you can make them transparent, or plot all your plots in the last one (scaled) Commented Aug 11, 2021 at 11:40
  • Thanks for your replies agaion. Yes if I can make that only with one axes I want to do that. And for the transparent, I put 'backgroundcolor','none' but it doesn't not work...phwww Commented Aug 11, 2021 at 11:45
  • You could normalize all the data, plot them on a single axis, and then use yticklabels with prefixes like \color{red}. Labels would be created using sprintf. But it is a bunch of work, not sure if it is worth the effort when one can use subplot. Commented Aug 11, 2021 at 12:43

2 Answers 2

2

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: enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot Cem! I didn't know that normalized function like that. When I use your codes and change the Y Values the axis changes also. But if I applied your code to my code, the axis doesn't change. I think it is problem of my GUI to call function and arguments.
I wrote another question in here. If you know something about that I'd be glad!
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.