Different grid lines color in MATLAB

조회 수: 139 (최근 30일)
Denis Perotto
Denis Perotto 2019년 7월 1일
댓글: Denis Perotto 2019년 7월 1일
Is it possible to change color of every single grid line? Not only for all X or Y lines.
I only know it is possible to change any label on axis like this:
ax = gca;
ax.YTickLabel{2} = '\color{green}T_{S}';

답변 (1개)

Jon
Jon 2019년 7월 1일
The grid is a property of the current axis. After you draw your figure, and add the grid, you can set the GridColor property of the current axis. Here's a little example. Note RGB colors are normalized values in range of 0 to 1.
% make up some data to plot
x = linspace(0,100);
y = x.^2 + 3;
% plot the data and add the grid
plot(x,y)
grid
% change the grid color, gca means get current axis, the colors are RGB values
set(gca,'GridColor',[0.1 0.2 0.9]) % a bluish color
  댓글 수: 9
Adam Danz
Adam Danz 2019년 7월 1일
편집: Adam Danz 2019년 7월 1일
xline & yline are great solutions for r2018b or later and those lines will extend if the axis limits are changed after they are drawn.
If you're plotting lines manually (as Jonathan proposed), the lines will not extend if the axis limits are increased which is why it's good to either set the desired axis limits prior to drawing those lines or make sure the line extend to the desired limits.
Denis Perotto
Denis Perotto 2019년 7월 1일
Okay, so it seems I have to create a custom grid of lines using 'yline' after all.

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

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by