How can I save an axes which has multiple coordinate systems?
43 次查看(过去 30 天)
显示 更早的评论
I have an UI which contains an axes with two Y-axis. I used the yyaxis command. How can I save the axes to png or an other data format? The problem is that when I save the whole figure, it will contain also parts of the UI Objects. The panels for example. Instead I want to save just the axes. The advice I found, was to copy the axes to a new figure and save it there. Sadly, copyobj is not working with axes with multiple coordinate systems. Can you help me?
Edit: its yyaxis not yyaxes
3 个评论
dpb
2018-8-19
编辑:dpb
2018-8-19
Was going to say "must not be doing it right" until was going to show--
>> hAx(1)=gca;
>> yyaxis right
>> hAx(2)=gca;
>> figure
>> copyobj(hAx,gcf)
Error using copyobj
Cannot copy the same object more than once to the same parent. Try calling COPYOBJ twice instead.
>> copyobj(hAx(1),gcf)
Error using copyobj
Object Copy of Axes with multiple coordinate systems is not supported.
>>
What a kick in the teeth; this is nasty. Add some ease of use over plotyy but lose some flexibility. "There is no free lunch."
All I can suggest is if this is important-enough without the accoutrements of the rest of the figure is to replot it for the purpose as "ordinary" figure or build the other plot with plotyy instead, saving the two axes handles which you could copyobj
回答(1 个)
jonas
2018-8-21
编辑:jonas
2018-8-21
Copyobj doesn't seem to work with yyaxis because you end up with a single axes object having multiple coordinate systems. You can avoid this situation altogether by not using yyaxis. Personally, I prefer this approach over yyaxis:
%%Create double yaxis
ax1=axes('yaxislocation','left');hold on
ax2=axes('yaxislocation','right','xcolor','none');hold on
set([ax1 ax2],'color','none')
linkaxes([ax1 ax2],'x')
%%Call axes and plot like this
axes(ax1)
h1=plot([0 1],[0 1])
axes(ax2)
h2=plot([0 1],[1 0])
%%Copy axes to new figure
figure;
copyobj(ax1,gcf)
copyobj(ax2,gcf)
An alternative would be to hide all UIobjects before saving the figure. However, then you have to 'unhide' after saving the figure.
uis=findobj(gcf,'type','UIControl')
set(uis,'visible','off')
% save...
set(uis,'visible','on')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!