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!