Make axis line invisible but not tick labels

89 vues (au cours des 30 derniers jours)
Yvan Becard
Yvan Becard le 25 Mai 2020
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'

Réponses (2)

Srivardhan Gadila
Srivardhan Gadila le 30 Mai 2020
Modifié(e) : Srivardhan Gadila le 11 Juin 2020
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 le 14 Août 2020
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

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by