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

1 Ansicht (letzte 30 Tage)
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');

Akzeptierte Antwort

jonas
jonas am 17 Aug. 2018
Bearbeitet: jonas am 17 Aug. 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 Kommentar
Hannes
Hannes am 17 Aug. 2018
Bearbeitet: Hannes am 17 Aug. 2018
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...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by