Make axis line invisible but not tick labels

49 次查看(过去 30 天)
I want to the make the X and Y axes invisible (not white), so I have used different ways:
set(gca,'xcolor','none') or gca.XAxis.Visible = 'off';
In both cases the axes disappear but so do the tick labels, which I want to keep. I've tried the following but to no avail:
gca.XAxis.Label.Color = [0 0 0]; gca.XAxis.Label.Visible = 'on'

回答(2 个)

Srivardhan Gadila
Srivardhan Gadila 2020-5-30
编辑:Srivardhan Gadila 2020-6-11
As per my knowledge w.r.t current documentation, I think there is no way to make borders dissapear along all the sides with tick labels to remain appeared.
The propety Box removes the box outline but only on the right and top sides of the box, so no use of using it.
Setting the ax.XAxis.Visible = 'off'; also makes the TickLabels invisible, so no use of this too.
If it helps, you can pass the Tick Labels together as one string to ax.XAxis.Label.String then set the ax.XAxis.Visible = 'off' & ax.XAxis.Label.Visible = 'on'. Do the siimilar thing w.r.t YAxis.

Marta Jimenez
Marta Jimenez 2020-8-14
I managed to solve a similar problem ... in case it can help someone.
First I created my plot, and when everything was there (labels, title, yticklabels...), I superimposed another axes.
hold on
b=barh(MyTable.Order,MyTable.NrElements,'FaceColor',BarsColor);
ax1=gca;
%...Rest of code:
%In my case I did not want the XTicks or labels either, but if you comment this part
% they will appear
set(ax1, 'XTick', []);
set(ax1,'TickLength',[0 0])
%Get rid of X axis overlapping a white one over
% In my case I wanted to keep the y axis, so I overwrited with black [0 0 0] but
% if you set it to [1 1 1] it will disappear too
ax2 = axes('Position',ax1.Position,...
'XColor',[1 1 1],...
'YColor',[0 0 0],...
'Color','none',...
'XTick',[],...
'YTick',[]);
hold off

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by