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!