如何使网格线与刻度线颜色相同

How to make grid lines the same colour as tick lines

参见下面的示例图,刻度线是黑色的,而网格线是灰色的。

我们怎样才能使它们相同?

这些 GridColor 方法都没有帮助:

%set(gca, 'GridColor', [0 0 0]);
ax = gca;
ax.GridColor = [0 0 0];

更改刻度线

参见NumericRuler properties。简而言之:

ax = gca;
ax.XAxis.Color = [.8,.8,.8]; % grey as RGB triplet
ax.YAxis.Color = 'blue';     % blue as option keyword

更改网格线

ax.GridColor 是对的,但默认情况下你有一个半透明的网格,所以还需要设置 ax.GridAlpha

ax = gca;
ax.GridColor = [0 0 0]; % Black as RGB, this is [0.15 0.15 0.15] by default (dark grey)
ax.GridAlpha = 1;       % Opaque, this is 0.15 by default (85% transparent) 

使它们相同

ax = gca;
% Set the grid to be opaque
ax.GridAlpha = 1;
% Set them to be the same colour
myColour = [0.4, 0.7, 1]; % Any RGB triplet etc.
ax.GridColor = myColour;
ax.XAxis.Color = myColour;
ax.YAxis.Color = myColour;