How to break ylabels of automatically created scatter plots in several lines?

1 次查看(过去 30 天)
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);
%%%%%%%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');

采纳的回答

jonas
jonas 2018-8-17
编辑:jonas 2018-8-17
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 个评论
Hannes
Hannes 2018-8-17
编辑:Hannes 2018-8-17
Great, Thx! It eventually works with adapting your code to cell inputs:
ylabelname=sprintf('%s \n %s \n %s',A.Name{row},A.Var{row},A.Unit{row})
ylabel(ylabelname,'FontSize',9 , 'Interpreter', 'none', 'FontWeight','bold');
Ok, I just realized that the same solution of course also applies to titles...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by