5

我想在此图中将 x 刻度标签向下移动:图

我不知道该怎么做?

这是我正在使用的脚本:

y=[0.5093 0.8526 0.9171];
x=[0 1600 1100];
hand =plot(y, 'ob-');
set(gca, 'XTick',1:3, 'XTickLabel',{'no interference' '1600' '1100'})
set(hand, 'LineWidth', 4);
set(hand, 'MarkerSize', 30);
set(findobj('type','text'),'FontSize',25);
set(gca,'FontSize',25);
set(findobj('type','axes'),'FontSize',25);
h=get(gca,'Title');
set(h,'FontSize',20);
4

2 回答 2

4

按照这个mathworks 解决方案中的示例,您可以使用该text函数在您希望的任何位置添加标签。

增加deltax 刻度标签和 x 轴之间较大间隙的值。

ytick编辑:添加了s 的自定义控件:stp更改每个刻度之间的步长的值。显然,更通用的解决方案也会自动识别刻度范​​围的端点。

figure(1), clf

% set data as your example
y=[0.5093 0.8526 0.9171];
x=[0 1600 1100];
Xt=1:length(x);
hand =plot(y, 'ob-');
set(gca, 'XTick',Xt);

stp=0.05;
Yt=0.5:stp:0.95;
set(gca, 'ytick', Yt)

% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .7])

ax = axis; % Current axis limits
axis(axis); % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4); % Y-axis limits
Xl = ax(1:2);

% Place the text labels -- the value of delta modifies how far the labels 
% are from the axis.
delta=0.1;
t = text(Xt, Yl(1)*ones(1,length(x))-delta, {'no interference' '1600' '1100'});
%set(t, 'HorizontalAlignment','left','VerticalAlignment','top')
set(t, 'HorizontalAlignment','center','VerticalAlignment','middle')

% Remove the default labels
set(gca,'XTickLabel','')

% and continue with your other settings as required
set(hand, 'LineWidth', 4);
set(hand, 'MarkerSize', 30);
set(findobj('type','text'),'FontSize',25);
set(gca,'FontSize',25);
set(findobj('type','axes'),'FontSize',25);
h=get(gca,'Title');
set(h,'FontSize',20);

text功能有很多可以配置的选项。

于 2013-05-20T21:40:01.823 回答
2

我认为大多数人想要的是可以在 2-3 行代码中运行的东西,不要介意一种快速而肮脏的方法。

这是无证的(学分转到此处)但可以正常工作:

    % adjust ticklabels away from axes
    a=gca;
    a.XRuler.TickLabelGapOffset = 8;
    a.YRuler.TickLabelGapOffset = 8;

用 Matlab 2019a 测试

于 2019-09-04T09:27:18.557 回答