Half-step transfer of the MATLAB axis

I am trying to arrange MATLAB marks to fit my grid, but I cannot find a good way to compensate for the marks.

Also, if I run set(gca,'XTickLabel',1:10), my x tick marks end in the range of 1 to 5. What gives?

enter image description here

+4
source share
2 answers

You need to move the ticks, but first get the tags and write them down after moving:

f = figure(1)
X = randi(10,10,10);
surf(X)
view(0,90)

ax = gca;
XTick = get(ax, 'XTick')
XTickLabel = get(ax, 'XTickLabel')
set(ax,'XTick',XTick+0.5)
set(ax,'XTickLabel',XTickLabel)

YTick = get(ax, 'YTick')
YTickLabel = get(ax, 'YTickLabel')
set(ax,'YTick',YTick+0.5)
set(ax,'YTickLabel',YTickLabel)

enter image description here


Or, if you know everything before, do it manually from the very beginning:

[N,M] = size(X)

set(ax,'XTick',0.5+1:N)
set(ax,'XTickLabel',1:N)
set(ax,'YTick',0.5+1:M)
set(ax,'YTickLabel',1:M)
+7
source

, , 2d-. , , , .

xlabels=1:1:10;                               %define where we want to see the labels
xgrid=0.5:1:10.5;                             %define where we want to see the grid  

plot(xlabels,xlabels.^2);                     %plot a parabola as an example
set(gca,'xlim',[min(xgrid) max(xgrid)]);      %set axis limits so we can see all the grid lines
set(gca,'XTickLabel',xlabels);                %print the labels on this axis

axis2=copyobj(gca,gcf);                       %make an identical copy of the current axis and add it to the current figure
set(axis2,'Color','none');                    %make the new axis transparent so we can see the plot
set(axis2,'xtick',xgrid,'XTickLabel','');     %set the tick marks to the grid, turning off labels
grid(axis2,'on');                             %turn on the grid

script :

enter image description here

0

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


All Articles