How do I save a figure with linked properties?

조회 수: 6 (최근 30일)
Fabian Gock
Fabian Gock 2018년 8월 6일
댓글: Adam Danz 2018년 8월 7일
I have a figure with two 3 dimensional axes that are linked via
linkprop([ax2 ax1], {'View', 'XLim','YLim','ZLim'})
I used two sets of axes, because i need two different colormaps for a imagesc and hist3 plot, that are overlaying.
When I save the figure using savefig, and open it again, linkprop is resetted. How can I save the figure with the linked properties?
Thanks in advance! -Fabian

채택된 답변

Adam Danz
Adam Danz 2018년 8월 6일
편집: Adam Danz 2018년 8월 6일
The documentation on linkprop recommends storing the link object that linkprop() produces in the object's UserData property. After re-opening the figure you could then access the linkprop object to restore its properties. Here is a simple example where I create two figures and link the properties of the first to the second. Then I save the 2nd figure and close both figures. Then I open the 2nd figure and apply the link object to it again. However, in this simple example when I open the 2nd figure the properties are maintained which makes me wonder how you're saving your figure; using savefig()?
% Create 2 figs; we'll use the first as the template
f1 = figure('name', 'fig1', 'color', 'b', 'NumberTitle', 'off');
f2 = figure('name', 'fig2');
% Copy properties to fig 2; store link object in fig 2
linkObj = linkprop([f1, f2], {'Color', 'NumberTitle'});
f2.UserData = linkObj;
% save figure 2 to current directory; close both figure and clear vars
savefig(f2, 'fig2')
close([f1,f2])
clear all
% open figure 2
f2 = open('fig2.fig');
% Restore properties stored in UserData
addtarget(f2.UserData, f2)
  댓글 수: 3
Fabian Gock
Fabian Gock 2018년 8월 7일
You actually helped me out a lot.
this
linkObj = linkprop([f1, f2], {'Color', 'NumberTitle'});
f2.UserData = linkObj;
solved my problem. Thanks!
Adam Danz
Adam Danz 2018년 8월 7일
Good! Its interesting that storing the linkObj output isn't necessary for a simple 2D plot but is needed for the 3D axis limits. Hmmm.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Purple에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by