Why delete(fin​dobj(gca,'​type', 'patch')) is not working for erasing scattered points ?

10 vues (au cours des 30 derniers jours)
Here's a simple snippet that shows that
delete(findobj(gca,'type', 'patch'))
is not working for erasing scattered points:
figure
x = [1,2,3,4]
y = [1,2,3,7]
scatter(x,y,50);
delete(findobj(gca,'type', 'patch')) % not working
%delete(findobj(gca,'SizeData', 50)) % does work
Uncommenting the last line solves the problem, but this is a workaround, or what ?

Réponse acceptée

Adam Danz
Adam Danz le 13 Jan 2020
Modifié(e) : Adam Danz le 14 Jan 2020
"Why delete(fin​dobj(gca,'​type', 'patch')) is not working for erasing scattered points ?"
Because s = scatter(___) produces a scatter object, not a patch object.
Instead,
delete(findobj(gca,'type', 'scatter'))
Or better yet, use the scatter output which does not require the use of the axis handle and is more responsible since you're deleting a specific object rather than deleting all existing matches to an object type within the current axes.
s = scatter(. . .);
delete(s)

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by