我正在尝试在我的情节中制作网格,我有其他更简单的情节,我设法显示网格,但不是在这个情节:
%The AXES command selects the set of axes to plot in,
axes(handles.viewCAM_handles.axes_accVelRatio);
% Plot velV and accV ratio with centered x and y axis
[AX] = plot(velV, accV);
grid on;
set(AX, 'LineWidth', 2);
xlabel('Velocity');
ylabel('Acceleration', 'Color', 'b');
xMax = max([max(velV) abs(min(velV))]);
yMax = max([max(accV) abs(min(accV))]);
if xMax >= 1
xMax = ceil(xMax);
else
xMax = round(xMax*10)/10;
end
if yMax >= 1
yMax = ceil(yMax);
else
yMax = round(yMax*10)/10;
end
axis([-xMax xMax -yMax yMax]);
y=get(gca,'ytick');
x=get(gca,'xtick');
hold on
Lx=line([x(1) x(length(x))],[0 0]);
Ly=line([0 0],[y(1) y(length(y))]);
set(Lx,'color','k');
set(Ly,'color','k');
for i=1:length(x)
plot(x(i),0,'kx');
text(x(i),-.01,num2str(x(i)));
end
for i=1:length(y)
plot(0,y(i),'kx');
text(-0.5,y(i),num2str(y(i)));
end
grid on;
set(gca,'yticklabel',[],'xticklabel',[],'ytick',[],'xtick',[]);
我在情节中间设置了原点,我为此绘制了线条,我认为问题与此有关。有什么想法吗?
我已尝试在此代码的其他位置放置“网格”但我无法显示网格。
答案 0 :(得分:0)
网格线与轴的x和y刻度相关。 因此,您可以更改删除刻度线的行:
set(gca,'yticklabel',[],'xticklabel',[],'ytick',[],'xtick',[]);
单独清除标签
set(gca,'yticklabel',[],'xticklabel',[])
或者您必须使用线条手动绘制网格(请参阅http://www.mathworks.com/matlabcentral/answers/102945-how-can-i-specify-the-spacing-between-minor-tick-marks-and-minor-grid-lines-in-my-figures-in-matlab)。