필터 지우기
필터 지우기

How to set the grid line of y-axis by 5 ?

조회 수: 8 (최근 30일)
Rahim Rahim
Rahim Rahim 2022년 7월 23일
답변: Star Strider 2022년 7월 23일
I want to add a grid on my plot. Unofrtunetely, I found only Grid normal and Grid miror,
I want to add a grid that appear every 5 value on y-axis, for example:

답변 (2개)

Voss
Voss 2022년 7월 23일
Maybe something like this?
ax = gca();
set(ax, ...
'XLim',[0.7 4.5], ...
'YLim',[0 40], ...
'XTick',1:4, ...
'YTick',0:5:40, ...
'GridColor','r', ...
'XGrid','on', ...
'YGrid','on');
ytl = get(ax,'YTickLabels');
ytl(2:2:end) = {''};
set(ax,'YTickLabels',ytl);

Star Strider
Star Strider 2022년 7월 23일
If you have R2018b or later, the easiest solution would likely be the xline and yline functions.
x = 0:5;
y = randi(40, size(x));
figure
plot(x, y)
xline(1:5,'-r')
yline(5:5:40,'-r')
yticks(0:10:40)
.

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by