如何隐藏轴但保留网格?

How to hide the axes but keep the grid?

如果我们有一个数字

plot(x, y);
grid on;

我们得到这样的结果

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

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

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

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

那么,如何隐藏 axistickslabels,留下 只有 plot and grid?

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

操作方法如下:

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];

您可以将 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')