How to clear boxplots?

3 ビュー (過去 30 日間)
Petra
Petra 2012 年 12 月 7 日
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

回答 (1 件)

Jonathan Epperl
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
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 ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by