Plot - Remove axis ticks but keep grid lines

조회 수: 135 (최근 30일)
Christopher McCausland
Christopher McCausland 2021년 9월 28일
댓글: Christopher McCausland 2021년 9월 28일
Hi,
I am producing a graph to view open source polysomnography data. I have several arrays in one plot window with an offset between them which is fairly standard. I wish to remove the y tick numbers as they aren't required and get in the way of some additional lables. I would like to also include some x and y axis gridlines.
I have implemented the following code below, however the 'set(gca,'ytick',[])' command makes the y gridlines not plot. How can I remove the ytick numbers on the y axis but keep the y gridlines?
Thanks in advance,
Christopher!
% Create a new empty figure
figure
% Remove y axis numbering
set(gca,'ytick',[])
% Set major Grid lines
ax.GridLineStyle = '--';
ax.GridColor = 'b';
ax.GridAlpha = 1;
grid on;
% Set minor Grid lines
ax.MinorGridLineStyle = '-';
ax.MinorGridColor = 'b';
ax.MinorGridAlpha = 0.5;
grid minor;

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 9월 28일
A couple things. You have discovered you have to have ticks to have a grid. However, labels are separate. Leave the ticks and remove the yticklabels.
Also, ax does not automatically refer to the axis properties. You must create ax as an axis object first for that to work. Your code is just creating a structure named ax.
Try this.
% Create a new empty figure
figure
ax = gca;
% Remove y axis numbering
yticklabels("")
% Set major Grid lines
ax.GridLineStyle = '--';
ax.GridColor = 'b';
ax.GridAlpha = 1;
grid on;
% Set minor Grid lines
ax.MinorGridLineStyle = '-';
ax.MinorGridColor = 'b';
ax.MinorGridAlpha = 0.5;
grid minor;
  댓글 수: 1
Christopher McCausland
Christopher McCausland 2021년 9월 28일
Hi Cris,
That makes much more sense and works perfectly. Thank you!
Christopher

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by