Set the position of the Xtick shortcuts

I want to move the x tick labels down in this image: fig

I'm not sure how to do this?

This is the script I use:

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); 
+5
source share
2 answers

Following the example of this mathworks solution , you can use the text function to add labels to any position you want.

Increase the delta value for a larger gap between the x tick marks and the x axis.

EDIT: added custom control ytick s: the stp value changes the pitch between each tick. Obviously, a more general solution will also automatically identify the endpoints of the tick range.

 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 (eg 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); 

The text function has many parameters that you can configure.

+4
source

I think most people want something that works in 2-3 lines of code, not to mention a quick and dirty approach.

This is undocumented (loans go to here ), but just works:

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

tested with Matlab 2019a

0
source

Source: https://habr.com/ru/post/1481692/


All Articles