Is it possible to delete "subplots"?

147 ビュー (過去 30 日間)
Mr M.
Mr M. 2015 年 4 月 24 日
回答済み: Omer Ferhat 2017 年 11 月 12 日
For example I have a figure and five plots on it. I would like to start a new figure with the same plots, except the last one. Is it possible to recall the previous ones?

回答 (5 件)

Thomas Koelen
Thomas Koelen 2015 年 4 月 24 日
編集済み: Thomas Koelen 2015 年 4 月 24 日
Yes it is:
figure
hold on
h1=subplot(1,2,1)
plot(1:10,'r');
h2=subplot(1,2,2)
plot(2:11,'g');
pause(2)
delete(h2)
however, you'll still see the empty space where the subplot was before.
  1 件のコメント
Thomas Koelen
Thomas Koelen 2015 年 4 月 24 日
Did you figure out how to make your markers transparant by the way? You asked the question yesterday, I answered but you didn't respond!

サインインしてコメントする。


Michael Haderlein
Michael Haderlein 2015 年 4 月 24 日
If you haven't already saved the handles when creating the axes, you can first get the handles with
haxes=get(gcf,'children');
and then recreate them with
haxes_new=copyobj(haxes(2:end),figure);
Of course, the position of the axes remains this way. Alternatively, you could only copy the plots with (haxes as before):
figure
for cnt=1:4
hplots=get(haxes(end-cnt+1),'children');
copyobj(hplots, subplot(2,2,cnt));
end
And the axes will be aligned as usual.
  1 件のコメント
Michael Haderlein
Michael Haderlein 2015 年 4 月 25 日
Mr. M has written: "No, I am not using subplots (sorry for the ""), just plots on each other! So I would like to keep for example some shapes or functions on the plot. Or I would like to keep some settings, for example axis, titles, legends, etc. But not all."
-----------------
My response:
Ok, no subplots here. I would copy the axes with copyobj:
ha_new=copyobj(gca,figure);
Then get the handles of the children with
hc=get(ha_new,'children');
and finally delete some of the children (less cruel than it sounds):
delete(hc(1:4))
deletes the 4 children which have been added latest. You could also specify certain properties of lines to delete:
delete(hc(cellfun(@(c) isequal(c,[0 0 1]),get(hc,'color'))))
deletes all blue lines.

サインインしてコメントする。


Omer Ferhat
Omer Ferhat 2017 年 11 月 12 日
You can delete subplots with
delete(subplot(X,Y,P))

Mr M.
Mr M. 2015 年 4 月 24 日
No, I am not using subplots (sorry for the ""), just plots on each other! So I would like to keep for example some shapes or functions on the plot. Or I would like to keep some settings, for example axis, titles, legends, etc. But not all.

Thomas Koelen
Thomas Koelen 2015 年 4 月 24 日
X=1:10;
Y=X.^2;
Z=X.^3;
figure
hold on
p1=plot(X,Y);
p2=plot(X,Z);
pause(2)
delete(p2)
  1 件のコメント
Mr M.
Mr M. 2015 年 4 月 24 日
thanks And what about settings? Is it possible to keep some settings?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by