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.

Heewonny
  • 25
  • 6
  • 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! – Ander Biguri Aug 11 '21 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](https://stackoverflow.com/questions/1719048/plotting-4-curves-in-a-single-plot-with-3-y-axes) – Heewonny Aug 11 '21 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) – Ander Biguri Aug 11 '21 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 – Heewonny Aug 11 '21 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`. – Cem Aug 11 '21 at 12:43
  • If setting the background color to none doesn’t work, try changing your graphics backend. – Cris Luengo Aug 11 '21 at 12:43
  • @Cem Thanks for your reply! Yes, all of them are normalized.... and I wanted to give a color on ticklabels after see the plot. But the plot hides so I couldn't do that. – Heewonny Aug 11 '21 at 13:14

2 Answers2

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

Cem
  • 1,276
  • 4
  • 17
  • 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. – Heewonny Aug 12 '21 at 07:02
  • I wrote another question in [here](https://stackoverflow.com/questions/68755070/call-variables-to-another-function-in-octave-gui). If you know something about that I'd be glad! – Heewonny Aug 12 '21 at 09:48
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
Cem
  • 1,276
  • 4
  • 17