How can I delete a plot among many other plots?
Show older comments
Hello. I tried to find an answer for this but the findobj didn't work for me.
load cities.mat
figure(1)
for i=1:9
plot(ratings(:,i),'DisplayName',num2str(categories(i,:)),'LineWidth',1)
hold on
end
lgd=legend('show')
ylim([0*10^4 6*10^4])
xlim([0 size(ratings,1)])
set(gca,'xtick',[0:50:300])
set(gcf,'position',[360 278 800 600])
title('Cities Data')
xlabel('Cities')
lgd.Position=[0.7134/1.07 0.6464/1.2 0.1741*1.3 0.2548*1.3]
I have different DisplayNames i.e climate, arts etc... and I want to delete the arts plot after using this code. How can I do that?
Thanks, Eran.
Accepted Answer
More Answers (1)
Walter Roberson
on 13 May 2017
delete( findobj(gcf, 'Name', 'arts') )
9 Comments
Eran Sandman
on 13 May 2017
Walter Roberson
on 13 May 2017
delete( findobj(gcf, 'DisplayName', 'arts') )
Eran Sandman
on 13 May 2017
Eran Sandman
on 13 May 2017
Walter Roberson
on 13 May 2017
R2017a:
L = plot(rand(1,10),'DisplayName','frodo');
hold on; L2 = plot(rand(1,10),'DisplayName','frodo2')
legend('show')
pause(10)
delete( findobj(gca, 'DisplayName','frodo') )
and away goes the item, and the legend for it as well.
The legend entry going away automatically is new in R2017a. In previous versions,
legend('show')
would probably re-create the legend.
Eran Sandman
on 14 May 2017
Edited: Eran Sandman
on 14 May 2017
Walter Roberson
on 14 May 2017
"I have different DisplayNames i.e climate, arts etc"
No, you do not: you have
plot(ratings(:,i), 'DisplayName', num2str(categories(i,:)), 'LineWidth', 1)
which is converting a number to a string and using that as the DisplayName. So like '17' for example. Not 'arts'
Eran Sandman
on 14 May 2017
Edited: Eran Sandman
on 14 May 2017
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!