plotyy messing up my gui

2 views (last 30 days)
Jose Ramos
Jose Ramos on 8 Jul 2012
I have a gui that has many buttons that plot something after pressing each button. All plots have the same dimension and are plotted on the same frame. So I decided to have one of these plots contain two graphs, using plotyy since the second graph has a different y axis. Now when I press a button, my plots come out bigger and outside the original frame. I managed to fix that but the new plots have the new axes and the old axes superimposed on them. I have tried to understand handles but it's like a foreign language to me. Does anyone know how I can eliminate the AX(2) properties? This seems to be the one messing me up. I just want all my buttons to plot in the correct spot.
  1 Comment
Yash
Yash on 8 Jul 2012
can you include another axis?

Sign in to comment.

Accepted Answer

Jose Ramos
Jose Ramos on 8 Jul 2012
Thanks Yash and Jan for your respective replies. Here's exactly what happens. I have a gui with something like 10 buttons. Each time I press a button it plots a function, i.e., autocorrelation, histogram, power spectral density, etc. Each plot has the same size and position on the screen. So one plot enters and next plot is replaced in exactly the same spot. To control the buttons I'm using a switch block. Thus the information gets destroyed after the the plot is done. The problem comes when one of those buttons plots a graph with two vertical axes, a left and a right. After that the remaining buttons work but they plot as a larger graph and not in the same position as before. It seems like the current axis is the right axis. Below is an example of what I'm talking about.
switch(action)
case 'residual' % Plots three graphs: the chosen lead, the residual,
subplot(3,1,1); % and the outliers, in a separate window created by
plot(t,w,'g'); % the residualgraph gui function.
ylabel('Normalized ECG Signal');
title('Lead');
subplot(3,1,2);
plot(t,x,'b',t,y,'r',t,z,'r',t,5*O,'y',t,-5*O,'y',t,4*O,'g',t,-4*O,'g');
title('Residual Plot $6\sigma$ = red Residual=blue');
ylabel('Standardized Error, $z_e(t)$');
subplot(3,1,3);
plot(t,e2,'b',t,sick,'r-',t,4.5*O,'y',t,4*O,'g')
title('Detection of Outliers Based on a Tracking Signal')
xlabel('Time (milliseconds)')
ylabel('Tracking Signal, $e_2(t)$')
case 'clean' % Plots the lead and its model.
%--------------------------------------------------------------------------
% High-pass filtering of ecg signal.
%-----------------------------------------------------------------
h_fig=findobj('Tag','Fig1');
g=get(h_fig);
L=length(x); % Length of the error signal.
XX=x; % Retain a copy for later use.
W=blackman(L); % Specify Blackman's window.
XW=W.*XX; % Multiply window and data.
UU=XW; % Retain a copy as input to the filter.
[H]=bandpass2(0.8,1,0.2,2,800,'off'); % Perform filtering operation.
ef=conv(UU,H); % Perform convolution.
a=length(H);
b=length(UU);
N=length(ef);
c=round((N-b)/2); % a, b, and c are length parameters.
ti=0:b-1; % set time axis.
[AX,H1,H2]=plotyy(t,x,ti,ef(c+1:c+b),'plot'); % plot with two y scales.
xe1=min(ef);
xe2=max(ef);
xe=max(abs(xe1),abs(xe2));
set(AX(2),'YTick',[linspace(-40*xe,40*xe,9)]);
yh2=linspace(-40*xe,40*xe,9);
set(AX(1),'Box','off','Ycolor',[0 0 0]);
set(AX(2),'Box','off','Ycolor',[0 0 0]);
set(AX(2),'XaxisLocation','top','XtickLabel',[])
set(AX(2),'ylim',[yh2(1) yh2(end)],'ytick',yh2);
set(get(AX(1),'Ylabel'),'String','$y(t)$ vs $y_{fitted} t)$','Color','k');
set(get(AX(2),'Ylabel'),'String','Amplitude (mV)','Color','k');
set(H1,'Color','b','LineStyle','.')
set(H2,'Color','g','LineStyle','-')
title('Original vs Fitted ECG Signal');
xlabel('Time (milliseconds) Original=red, Model=blue');
xy1=min(x);
xy2=ceil(1.10*max(x));
rm=mod(xy2,10);
if (rm==0)
dx=xy2/10;
else
xy2=xy2-rm;
dx=xy2/10;
end
set(AX(1),'YTick',[0:dx:xy2]);
V=[0 600 0 xy2];
axis(V);
h1=text(375,0.90*xy2,'*****');
h2=text(410,0.90*xy2,'$y(t)$');
h3=text(375,0.85*xy2,'--------');
h4=text(410,0.85*xy2,'$y_{fitted}(t)$');
h5=text(375,0.80*xy2,'--------');
h6=text(410,0.80*xy2,'Residual after highpass filtering');
set(h1,'Color','b');
set(h2,'Color','k');
set(h3,'Color','r');
set(h4,'Color','k');
set(h5,'Color','g' );
set(h6,'Color','k');
set(AX(1),'NextPlot','add')
plot(t,y,'r')
axes(AX(2));
ylabl=get(gca,'YLabel');
set(ylabl,'Position',get(ylabl,'Position') - [55 0 0]);
set(gca,'YTickLabel',num2str(reshape(get(gca,'YTick'),[],1),'%0.2f '));
case 'hgram' % Plots the histogram of the lead.
hist(x,ceil(sqrt(length(x))));
title('Histogram of the Lead');
xlabel('Range of Data');
ylabel('Frequency');
end
The problem is with the middle case "clean", because of the two axes. Does anyone know how I can revert to the single x, y axis pair? I am going crazy over this.
Jose
  1 Comment
Jan
Jan on 8 Jul 2012
Please add information required to understand the question by editing the question and not as answer. Most of all if you accept your answer, the thread looks like it is solved.
I still do not get the problem. When the following plots appear in an AXES, which is large than you want it to be, setting the size to the wanted value would be an obvious solution.

Sign in to comment.

More Answers (1)

Jan
Jan on 8 Jul 2012
The question is not clear to me. Perhaps understanding the handle concept allows you to solve the problem already: A "handle" is a value of type double (but it could be any other type also, e.g. a string, but this detail does not matter), which addresses each GUI object unequivocally. Using this handle allows to set the properties of an object later on or to use a specific object as parent of others.
Axes1H = subplot(1,2,1); % Now AxesH is the AXES object
Axes2H = subplot(1,2,2);
% Show all properties:
get(Axes1H)
% Set a specific property:
set(Axes2H, 'Color', [1,0,1]);
% Draw to a specific axes:
LineH = line(1:10, rand(1,10), 'Parent', Axes1H);
% Show properties of the line:
get(LineH)
Now consider that plotyy creates two axes, while the one in the foreground has a transparent background color. Perhaps you can use the two axes handles replied by plotyy to perform, what you want.

Categories

Find more on Two y-axis in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!