0

I am trying to make two plots in the same GUI figure that has 2 different axes. I would like one plot in one axes whereas the next one in the other. However, both my plots are generated from a single function, which I call in the GUI with a push button.

When I write axes() before the 2nd plot inside the function, I get a third axes which is misplaced. If I omit the axes() call, I get both plots in the same axes. How can I plot the second graph in the second axes?

GUI

function pushbutton1_Callback(hObject, eventdata, handles)
---------
---------
---------
axes(handles.axes1);
     kendrickplot(n,alpha,em,infile,outfile);
---------

Function

function [ynew,xnew]=kendrickplot(n,alpha,em,infile,outfile)
---------
---------
scatter(xnew,ynew,'b.')
xlim([0,max(a(:,4))])
ylim([min(a(:,5)),max(a(:,5))])
hold on
plot(xnew,n*(ones(length(xnew))),'r')
scatter(a(:,4),a(:,5))
end
Vahe Tshitoyan
  • 1,439
  • 1
  • 11
  • 21
Rudstar
  • 101
  • 2
  • Add the axes handle to the plotting functions `scatter` and `plot` – EBH Jul 13 '17 at 08:22
  • 2
    Try passing `handles.axes1` and `handles.axes2` to your function and calling `axes(h1);` and `axes(h2)`before each plot – Vahe Tshitoyan Jul 13 '17 at 08:25
  • @VaheTshitoyan could you please give an example of what you're suggesting? – Rudstar Jul 13 '17 at 08:34
  • 2
    modify your function: `function [ynew,xnew]=kendrickplot(n,alpha,em,infile,outfile, h1, h2)`. Inside the function, add `axes(h1)` before the first plot and `axes(h2)` before the 2nd plot. In your callback, call the function like this `kendrickplot(n,alpha,em,infile,outfile, handles.axes1, handles.axes2);`. Haven't tested this. – Vahe Tshitoyan Jul 13 '17 at 08:49
  • @VaheTshitoyan Yes, it works. Thank you, so much! – Rudstar Jul 13 '17 at 09:04
  • @Rudstar Glad it helped. I'll post it as an answer for future readers, consider accepting it. – Vahe Tshitoyan Jul 13 '17 at 09:10

1 Answers1

3

One way is to pass the handles of the axes to the function that does the plotting.

  1. modify your function to accept the plot handles:

    function [ynew,xnew]=kendrickplot(n,alpha,em,infile,outfile, h1, h2)

  2. Inside the function, add axes(h1) before the first plot and axes(h2) before the 2nd plot.

  3. In your callback, call the function like this kendrickplot(n,alpha,em,infile,outfile, handles.axes1, handles.axes2);.

Vahe Tshitoyan
  • 1,439
  • 1
  • 11
  • 21