How to clear boxplots?
조회 수: 3 (최근 30일)
이전 댓글 표시
Dear Matlab-Users
Is there a way to efficiently delete all elements of a boxplot from a figure? This implementation does the job
delete(findobj(gca,'Tag','Box')); delete(findobj(gca,'Tag','Upper Adjacent Value')); delete(findobj(gca,'Tag','Lower Adjacent Value')); delete(findobj(gca,'Tag','Upper Whisker')); delete(findobj(gca,'Tag','Lower Whisker')); delete(findobj(gca,'Tag','Median')); delete(findobj(gca,'Tag','Outliers')); delete(findobj(gca,'Type','patch')); % the boxes are colored
But it is very slow and not feasible, since I deal with many axes (which are integrated in a GUI). This GUI allows the user to adjust the matrix X which is depicted by boxplot(X). I think that cla is not an option, since the axes contain other elements which need to stay visible. Any ideas?
boxplot(X,'Tag','box_plot'); delete(findobj(gca,'Tag','box_plot'));
is not allowed. How can I avoid this frequent call of findobj?
Thanks in advance.
Petra
댓글 수: 0
답변 (1개)
Jonathan Epperl
2012년 12월 7일
You should capture the handles of the objects created by boxplot in a variable, then you can delete them all together without having to find them every time:
load carsmall
h = boxplot(MPG,Origin); % Now h contains the handles to every object created
text(3, 40,'blabla')
delete(h) % Note that the boxes and stuff are gone, the text is still there
댓글 수: 1
Matt Fig
2012년 12월 7일
Petra, with graphics objects (figures, axes, lines, etc) it is always worthwhile to see if the creation call returns a handle. This will help you in further manipulations down the road, more than just deleting things....
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!