关于Matlab:如何隐藏轴但保持网格?

How to hide the axes but keep the grid?

如果我们有身材

1
2
plot(x, y);
grid on;

我们得到这样的东西

enter image description here

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

1
2
3
4
axis off
set(gca,'xtick',[])
set(gca,'ytick',[])
set(gca,'visible','off')

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

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

那么,如何隐藏轴,刻度线和标签,而只保留绘图和网格?


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

1
2
3
4
5
6
7
8
9
10
%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


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

enter image description here

方法如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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];