How to make only x-axis invisible (y-axis stays visible)?

1 297 views (last 30 days)
Csaba on 23 May 2013
Edited: Rini Varghese on 14 Apr 2022
I have two axes (top, bottom) in a GUI. I do not want the x-axis of the top ghraph to be present (because it is the same as the bottom x-axis). I could not find how to handle separately the x and y axis visibility.

Answers (10)

Muhammad Shah
Muhammad Shah on 17 Dec 2018
This Question is posted in 2013, but still last week got more than a thousand views, and I also needed this info, and I got very helpful information in this post, but surprizingly later I got an other solution in Matlab documentation and that was not yet here, and it is probably the smalest code, and I tested it and it worked nice, so I decided to addd it, here it is:
axis off ;
And thats it your axes are gone.
Luca Nagel
Luca Nagel on 8 Jul 2021
Dear Muhammad, thank you this was really helpful!

Sign in to comment.

Johann Riemensberger
Johann Riemensberger on 27 Oct 2016
Hi, axes('Color','none','XColor','none');
works for me Bests Johann

Wayne King
Wayne King on 23 May 2013
without seeing your code, a simple way is just to set the 'xtick' property to []
Csaba on 24 May 2013
Sorry, no. It makes the axis white but I have a picture behind the graph. So white axis (and actually any colors) are visible in my case. I do not want the x-axis at all.

Sign in to comment.

Jorge Mariscal Harana
Jorge Mariscal Harana on 5 Jul 2017
Edited: Jorge Mariscal Harana on 12 Sep 2017
ax1.YAxis.Visible = 'off'; % remove y-axis
ax1.XAxis.Visible = 'off'; % remove x-axis
Hope that helps, J
  1 Comment
Walter Roberson
Walter Roberson on 12 Sep 2017
Note: this uses syntax and properties available from R2014b, and so cannot could not have been used in the 2013 time-frame the question was originally asked for.

Sign in to comment.

Kyle Henderson
Kyle Henderson on 3 Dec 2017

Rini Varghese
Rini Varghese on 9 Oct 2018
Edited: Rini Varghese on 14 Apr 2022
Try the following:
h = gca;
h.XAxis.Visible = 'off';
Abdul Basith Ashraf
Abdul Basith Ashraf on 11 Nov 2019
This is better
If I set
the grid will also vanish.
But with your code, the grid stays . Thanks

Sign in to comment.

John Barber
John Barber on 24 May 2013
This solution might be overkill, but you can get that effect with my File Exchange program 'oaxes', available here: The following will show only a y axis at the left edge of the plot:
oa = oaxes;
oa.XAxisLine = 'off';
oa.XLabel = '';
oa.YLabel = '';
oa.Arrow = 'off';
oa.Origin = [-Inf -Inf 0];
% If you want the normal y label to be visible:
ylabel('my y axis...')
This should get you close to what you are looking for. The oaxes documentation will give you more information about the properties used in the example above, including an explanation of the difference between the oaxes 'YLabel' property which is set to empty above, and the parent axes' 'YLabel' text object. The main difference in appearance I am getting is that the oaxes ticks are bidirectional (they extend out on both sides from the axes line), while a normal axes has ticks that only extend to one side. Currently, there is no way to change this in oaxes, but I might add it in a future release.

José-Luis on 24 May 2013
Edited: José-Luis on 24 May 2013
h = axes;
pos = get(h,'Position');
new_h = axes('Position',pos);
linkaxes([h new_h],'y');
pos(3) = eps; %Edited here
Jan on 24 Nov 2017
[EDITED, moved from flag] andreas jensen wrote:
Overly complicated and doesn't work

Sign in to comment.

Chintan on 17 May 2014
Turn Box off, it usually works.

Martin on 24 Mar 2016
I solved something similar that way:

Community Treasure Hunt

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

Start Hunting!