필터 지우기
필터 지우기

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

조회 수: 2 (최근 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