How to break ylabels of automatically created scatter plots in several lines?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I post-process data tables, which result from Design of Experiments with m input parameters, n output parameters and > 100 evaluations/lines. I use scatter plots, which are automatically set up in m*n subplots, such that each row of scatter plots shows the effect of input parameters whereas each column of scatter plots shows the impact on the output parameters. The name of the input and output parameters are currenlty displayed only above the first row and left of the first column of scatter plots in order to save as much space between the scatter plots as possible. Above the first row I use plot title and was able to break the very long title (name + unit)
titlename=strcat(A.Name(col+NumIn),' (',A.Unit(col+NumIn),')');
title(titlename,'FontSize',9, 'Interpreter', 'none','Rotation',0);
in several lines according to this code ( https://de.mathworks.com/matlabcentral/answers/224185-how-to-make-long-title-for-a-plot-with-automatic-line-breaks ):
%%%%%%%START BREAKING TITLE LINE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ha=gca; NoCharPerLine= cellfun('length',titlename)-cellfun('length',A.Unit(col+NumIn))-2; % or whatever you want...
if ismatrix(ha(end).Title.String) && size(ha(end).Title.String,2)>NoCharPerLine
II=strfind((ha(end).Title.String(1:NoCharPerLine)),' '); % find last occurence of a space
LastSpaceIndex=II(end);
ha(end).Title.String={ha(end).Title.String(1:LastSpaceIndex-1) ;
ha(end).Title.String(LastSpaceIndex+1:end)};
end
if iscell(ha(end).Title.String)
while size(ha(end).Title.String{end},2)>NoCharPerLine
STR=ha(end).Title.String{end};
II=strfind(STR,' '); % find last occurence of a space
LastSpaceIndex=II(end);
ha(end).Title.String{end}=STR(1:LastSpaceIndex-1);
ha(end).Title.String{end+1}=STR(LastSpaceIndex+1:end);
end
end
%%%%%%%END BREAKING TITLE LINE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
My question is now how to deal with the automatically concatenated ylables (name+variable+unit) ?
ylabelname=strcat(A.Name(row),' _ ',A.Var(row),' (',A.Unit(row),')');
ylabel(ylabelname,'FontSize',9 , 'Interpreter', 'none', 'FontWeight','bold');
0 Commenti
Risposta accettata
jonas
il 17 Ago 2018
Modificato: jonas
il 17 Ago 2018
Like this?
ylabelname=sprintf('%s_{%s} (%s)',A.Name(row),A.Var(row),A.Unit(row))
ylabel(ylabelname,...)
You can also use sprinfc (undocumented) to get a cell array of labels. Something like this
ylabelnames=sprintfc('%s_{%s} (%s)',A.Name,A.Var,A.Unit)
Should give you a list of ylabelnames.
1 Commento
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Discrete Data Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!