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

时间:2018-02-08 16:53:17

标签: matlab plot matlab-figure

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

plot

我们怎样才能使它们一样?

这些GridColor方法都没有帮助:

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

1 个答案:

答案 0 :(得分:4)

更改刻度线

请参阅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;