Why does copyobj() fail to copy over title fontsizes (and also colorbars and colormaps)?
Afficher commentaires plus anciens
I am attempting to copy a set of subplot axes from one figure to another with copyobj. Everything seems to copy over quite nicely except for the title FontSizes, as illustrated in the example below. Does anyone know why?
h1=figure;
ax(1)=subplot(1,2,1);
plot(1:5,'rx:'); axis square
title('A','FontSize',15);
ax(2)=subplot(1,2,2);
plot(rand(1,5),'sb--'); axis square
title('B','FontSize',15);
h2=figure;
for i=1:2
copyobj(ax(i),h2);
end
4 commentaires
Paul
le 27 Avr 2021
I don't know why this happens but I suspect that there are some under-the-hood linkages in the axes object between various properties that control the title font size and maybe those linkages break or don't get copied over correctly. Did you try not setting TitleFontSizeMultiplier instead of setting the FontSize? I tried it for a full size axes (as opposed to a subplot where FontSizeMode might come into play?) and it seemed to work ok.
I think @Paul is on the right track. The fontsize multipliers of the new axes seem to take precedence over the fontsize properties of nested text objects.
The same problem happens if you set xlabel(ax(2),'X','fontsize',20) since the axes contain a LabelFontSizeMultiplier property.
One way to get around this is by copying the titles which are just text objects, but you'll need to remove the initial copy of the titles containing the wrong fontsize.
h1=figure;
ax(1)=subplot(1,2,1);
plot(1:5,'rx:'); axis square
title('A','FontSize',15);
ax(2)=subplot(1,2,2);
plot(rand(1,5),'sb--'); axis square
title('B','FontSize',15);
h2=figure;
for i=1:2
newax = copyobj(ax(i),h2);
newax.Title.String = ''; % clear copied title
copyobj(ax(i).Title,newax) % copy original title & props
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Color and Styling dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!












