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

554 ビュー (過去 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 Center および File ExchangeTwo y-axis についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by