필터 지우기
필터 지우기

How to avoid Matlab keeping old labels on my axis when redrawing

조회 수: 3 (최근 30일)
Paulo F.
Paulo F. 2014년 8월 5일
댓글: Paulo F. 2014년 8월 12일
Hi, I wish to thank you in advance for any help you can provide. I am having a serious headake trying to get a GUI with a couple of plots inside which correctly update as I change some parameters.
The think is the following, my GUI accepts some parameters plus a button and generates two plots and show them in their respective axes. After a while, I managed so that works in the way that I can change some parameters, press the button again and I wanted to update the plots.
The problem is that the new plots write the axis values over the old ones (they might change with the parameters) and that end up being a mess (you can see it in the picture, the Y axis is overwritten too, but only looks like "Bold" because the values are consistently the same, as that axis represents a probability).
function start_Callback(hObject, eventdata, handles)
myhandles = guihandles(bidding);
%Get the Plots Working
set(myhandles.axes1, 'NextPlot', 'new')
set(myhandles.axes2, 'NextPlot', 'new')
hist_prec=200;
%Get the variables declared by the user
load 'var.mat'
...
now_case=round(rand()*(ns*nbid));
%Plotting
min_interesting=max(-10*v+ob_value,min(min([mb;co])));
max_interesting=min(10*v+ob_value,max(max([mb;co])));
axes(myhandles.axes1)
cla(myhandles.axes1)
[x n]=hist(co(:),hist_prec);
xx=[];
for i=1:size(x,2)
xx=[xx;sum(x(1:i)/sum(x))];
end
[A B C]=plotyy(n,x,n,xx,'bar','plot');
set(C,'linestyle','-','linewidth',1.5, 'Color', 'red');
set(B,'FaceColor', 'blue');
save 'temp.mat'
axes(myhandles.axes2)
cla(myhandles.axes2)
[D E F]=plotyy(n,ep,n,xx,'bar','line');
set(handles.axes1,'XMinorTick','on')
set(F,'linestyle','-','linewidth',1.5, 'Color', 'red');
set(E,'FaceColor', 'blue');
hold on; tar=plot(n,target); hold off;
set(tar,'color','g');
linkaxes([myhandles.axes1 myhandles.axes2],'x');
guidata(hObject, handles);
That is the code related to the graphs inside the callback. Again I appreciate any help you can provide.
Cheers!
  댓글 수: 2
Supreeth Subbaraya
Supreeth Subbaraya 2014년 8월 8일
Can you provide a piece of your code and data with which we can reproduce the problem?
Paulo F.
Paulo F. 2014년 8월 12일
It is above, the variables and data are simply a vector generated randomly from some distribution. Thanks

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2014년 8월 8일
Please attach a screenshot. It looks like you're calling cla('reset') so that should wipe out all old information and start fresh. However you're only calling it on axes2, not on axes1. Maybe you should also call it on axes1 also. And you have a linkaxes. Why did you call linkaxes()?

Paulo F.
Paulo F. 2014년 8월 12일
편집: Paulo F. 2014년 8월 12일
Thanks for the answers, I thought that I had attached a picture of it, but here it goes. I do call cla('reset') for axis1 too. The first is axis1 and the second axis2.
Best and thanks!
  댓글 수: 2
Image Analyst
Image Analyst 2014년 8월 12일
Why is linkaxes called?
Paulo F.
Paulo F. 2014년 8월 12일
Hi, I use it to compare both graphs, the series are different versions of the data, so I want them to be both graphs compared. Nevertheless I tried it without likaxes and the problem is still there.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by