What should I do to solve the problem that the content of the text added in the matlab drawing window is outside of the figure?
조회 수: 2 (최근 30일)
이전 댓글 표시
My code is as follows:
bp = boxplot(data_all);
set(bp,'LineWidth',1);
ax = gca;
ax.TickLength = [0.01 0.01];
ax.LineWidth =1;
ax.XTickLabel = {"A" 1:18};
ax.XColor ='K';
ax.FontName = 'Arial';
ax.FontSize = 10;
ax.XLabel.String = 'model';
ax.XLabel.FontName = '宋体';
ax.XLabel.FontSize = 14;
ax.XLabel.FontWeight = 'bold';
ax.YLabel.String = 'p/mm';
ax.YLabel.FontName = '宋体';
ax.YLabel.FontSize = 14;
ax.YLabel.FontWeight = 'bold';
xname = cmip.Model;
xname = string(xname);
xname = ["观测值";xname];
xname = ["A" ; string(1:N)'] + '-'+ xname;
h = text(20,mean(ax.YLim),xname,'HorizontalAlignment','left');
h.FontSize = 10;
Thanks you!
Best wishes!
댓글 수: 0
채택된 답변
Voss
2022년 3월 28일
편집: Voss
2022년 3월 28일
You can adjust the axes and text Positions after everything else. See the bottom of the code below.
% made up data:
data_all = randn(100,19);
bp = boxplot(data_all);
set(bp,'LineWidth',1);
ax = gca;
ax.TickLength = [0.01 0.01];
ax.LineWidth =1;
ax.XTickLabel = {"A" 1:18};
ax.XColor ='K';
ax.FontName = 'Arial';
ax.FontSize = 10;
ax.XLabel.String = 'model';
ax.XLabel.FontName = '宋体';
ax.XLabel.FontSize = 14;
ax.XLabel.FontWeight = 'bold';
ax.YLabel.String = 'p/mm';
ax.YLabel.FontName = '宋体';
ax.YLabel.FontSize = 14;
ax.YLabel.FontWeight = 'bold';
% made up names:
xname = {'CESIII'; 'CMCCCC'; 'CMCBBB'; 'MPIII'; 'MRIIJKLMN'};
N = numel(xname);
xname = string(xname);
xname = ["观测值";xname];
xname = ["A" ; string(1:N)'] + '-'+ xname;
h = text(20,mean(ax.YLim),xname,'HorizontalAlignment','left');
h.FontSize = 10;
% adjust the axes width (ax.Position(3)) and text x (h.Position(1))
% by the width of the text (h.Extent(3)):
% need ax and h to be in the same Units:
h.Units = 'pixels';
ax.Units = 'pixels';
% perform the adjustment:
ax.Position(3) = ax.Position(3)-h.Extent(3);
h.Position(1) = h.Position(1)-h.Extent(3);
% restore the old Units:
ax.Units = 'normalized';
h.Units = 'data';
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!