In MATLAB, is there a way to set the GRID at a spacing different from the ticks on the axes?

조회 수: 553 (최근 30일)
In MATLAB, is there a way to set the GRID at a spacing different from the ticks on the axes?

채택된 답변

MathWorks Support Team
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])

추가 답변 (1개)

Udo Ruprecht
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
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 CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by