How to clear boxplots?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Jonathan Epperl
le 7 Déc 2012
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 commentaire
Matt Fig
le 7 Déc 2012
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....
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!