2017-03-07 21 views

回答

2

作为一种变通方法,你可以把两个主要和次要网格线,但设置主要的对背部颜色是这样的:

ax = axes; 
grid(ax,'on'); 
grid(ax,'Minor'); 
set(ax,'GridColor',get(ax,'Color')) 
set(ax,'MinorGridLineStyle','-') 
set(ax,'TickLength',[0;0]); 

其中给出: enter image description here

0

我不知道具体的matlab函数来完成这个。

作为一个解决方案,你可以自己与垂直线和水平线0.5画出格子,1.5,2.5,...

+0

我认为这会是一个相当普遍的特征,尤其是因为直方图和酒吧地块通常会需要它。 – TYL

+0

希望别人知道更好的解决方案。您可以尝试查看matlab的源代码,看看它们是如何做到的。 – m7913d

0

我也通过画我自己的次要网格线和不显示主网格线发现了另一种方式。

figure1 = figure; 
axes1 = axes('Parent',figure1,'ZGrid','on','XGrid','on',... 
    'YTickLabel',{'','1','2','3', ''},... 
    'YTick',[0 1 2 3 4 ],... 
    'YGrid', 'off') 

ylim([0.5 3.5]); 
xlim([0 20]); 
% gridlines --------------------------- 
hold on 
g_y=[0.5:1:4]; % user defined grid Y [start:spaces:end] 
g_x=[0:2:20]; % user defined grid X [start:spaces:end] 

for i=1:length(g_y) 
    plot([g_x(1) g_x(end)],[g_y(i) g_y(i)],'k-') %x grid lines 
end 

输出:

enter image description here

幸得https://au.mathworks.com/matlabcentral/answers/95511-in-matlab-is-there-a-way-to-set-the-grid-at-a-spacing-different-from-the-ticks-on-the-axes