In MATLAB, is there a way to set the GRID at a spacing different from the ticks on the axes?
296 次查看(过去 30 天)
显示 更早的评论
In MATLAB, is there a way to set the GRID at a spacing different from the ticks on the axes?
采纳的回答
MathWorks Support Team
2009-6-27
Currently the ticks and grid line spacing are associated and so the only way to change grid spacing is to change the tick spacing. Here are some examples:
figure
plot(1:100)
set(gca,'xtick',[0:13:100])
set(gca,'ytick',linspace(0,100,13))
% The following code changes the minor grid
% spacing by adjusting the tick spacing:
figure
plot(1:100);
grid on
grid minor
set(gca,'xtick',[0:50:100])
set(gca,'ytick',[0:50:100])
0 个评论
更多回答(1 个)
Udo Ruprecht
2015-2-6
I have another idea
x=[20:0.1:80];
y=sin(x);
plot(x,y,'r','Linewidth',2)
ylim([0 4]);
xlim([0 100]);
% gridlines ---------------------------
hold on
g_y=[0:0.1:4]; % user defined grid Y [start:spaces:end]
g_x=[0:2:100]; % user defined grid X [start:spaces:end]
for i=1:length(g_x)
plot([g_x(i) g_x(i)],[g_y(1) g_y(end)],'k:') %y grid lines
hold on
end
for i=1:length(g_y)
plot([g_x(1) g_x(end)],[g_y(i) g_y(i)],'k:') %x grid lines
hold on
end
print(1,'-dpng','-r300','K1') %save plot as png (looks better)
1 个评论
Hugh
2015-8-6
I voted for this answer because I also tend to build my own grid from lines. I use it to get the grid on top of an "area" plot style and to emphasize the baseline (typically zero value) with a thicker line.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!