如何隐藏轴但保持网格?

时间:2019-07-17 12:50:28

标签: matlab plot hide customization matlab-figure

如果我们有身材

plot(x, y);
grid on;

我们得到这样的东西

enter image description here

但是现在,我希望隐藏轴,所以我尝试了以下命令:

axis off
set(gca,'xtick',[])
set(gca,'ytick',[])
set(gca,'visible','off')

他们一起成功隐藏了轴,但是网格也被删除了

set(gca, 'xticklabel', [])可以隐藏标签,但不能隐藏轴。

因此,如何隐藏标记标签,而仅保留 情节网格

2 个答案:

答案 0 :(得分:5)

您可以将XcolorYcolor设置为none,这样就不会显示轴:

%dummy data
x = [-5:.1:5];
y = normpdf(x,0,1);
plot(x, y);

%grid on
grid on;

%Set the axis color to none.
set(gca,'XColor','none','Ycolor','none')

enter image description here

答案 1 :(得分:2)

我不确定我是否了解您想要实现的目标,但是如果这就是您的意思,

enter image description here

方法如下:

function [] = q57076281()
% Plot some data with a grid:
x = linspace(0,2*pi,100);
y = sin(x);
figure(); hP = plot(x,y); hAx = hP.Parent; 
grid(hAx, 'on');

% Remove the box:
box(hAx, 'off'); 

% Hide the labels:
set(hAx, 'XTickLabel', [], 'YTickLabel', []);

% Hide the axes:
hXl = struct(hAx.XAxis).Axle; hXl.Visible = 'off';
hXl = struct(hAx.YAxis).Axle; hXl.Visible = 'off';

% Hide the ticks:
hAx.TickLength = [0,0];