copy legend information - 2014b

26 ビュー (過去 30 日間)
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 10 月 4 日
コメント済み: Phuc Thien NGUYEN 2016 年 6 月 28 日
Hi, I want to copy few figures into a new figure with subplots. Hence as the initial step i intend to copy axes and legend information. In 2014b legend information saved as a object type.
% existing figure
h = surf(peaks);
colormap hsv
legend('temperature')
% new figure
fig = figure;
ax = axes;
new_handle = copyobj(h,ax);
colormap(fig,hsv)
view(ax,3)
grid(ax,'on')
How can I import the legend data and position to the new figure in matlab 2014b.

回答 (1 件)

Vivek Jadye
Vivek Jadye 2014 年 10 月 4 日
It is quite easy to copy axes and corresponding legend to a new figure. All you have to do is to use copyobj function as follows.
If you want to copy a specific axes and corresponding legend to a new figure it could be done this way
% existing figure
h = surf(peaks);
colormap hsv
leg = legend('temperature'); %Store legend object for copying
ax = findobj(gcf,'type','axes'); %Retrieve the axes to be copied
% new figure
fig = figure;
copyobj([leg,ax],fig);
colormap(fig,hsv);
If you intend to copy every figure child to a new figure you can simply do the following.
% existing figure
h = surf(peaks);
colormap hsv
legend('temperature');
oldfig = gcf;
% new figure
fig = figure;
copyobj(oldfig.Children,fig);
colormap(fig,hsv);
Hope this helps.
Cheers!
  3 件のコメント
Keith Rogers
Keith Rogers 2015 年 7 月 15 日
Looks like you can get the legend handle for a particular axes object with syntax like "legh = legend(ax)"
You can also do legend(ax,'show') or legend(ax,'hide')
Phuc Thien NGUYEN
Phuc Thien NGUYEN 2016 年 6 月 28 日
Great! It works perfectly. Thank you, Keith Rogers.

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

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by