How to make only x-axis invisible (y-axis stays visible)?
显示 更早的评论
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.
Csaba
回答(11 个)
Wayne King
2013-5-23
without seeing your code, a simple way is just to set the 'xtick' property to []
plot(randn(100,1));
set(gca,'xtick',[])
3 个评论
Csaba
2013-5-23
Wayne King
2013-5-23
Does this get closer?
subplot(211)
plot(randn(100,1))
set(gca,'xtick',[]);
set(gca,'xcolor',[1 1 1])
subplot(212)
plot(randn(100,1))
Csaba
2013-5-24
Muhammad Shah
2018-12-17
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.
Johann Riemensberger
2016-10-27
7 个投票
Hi, axes('Color','none','XColor','none');
works for me Bests Johann
Jorge Mariscal Harana
2017-7-5
编辑:Walter Roberson
2023-5-27
Hi,
Try:
ax1.YAxis.Visible = 'off'; % remove y-axis
ax1.XAxis.Visible = 'off'; % remove x-axis
Hope that helps, J
3 个评论
Walter Roberson
2017-9-12
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.
Ankit Labh
2023-5-27
How about removing only one y axis (say right side) and not both?
Thanks
Florens Helfferich
2023-11-27
@Ankit Labh ax1.Box = false;
This removes both the top and right side axes, but not the left and bottom axes.
Rini Varghese
2018-10-9
编辑:Rini Varghese
2022-4-14
Try the following:
h = gca;
h.XAxis.Visible = 'off';
2 个评论
Cg Gc
2019-2-14
This works great. Thank you.
Abdul Basith Ashraf
2019-11-11
This is better
If I set
set(gca,'xtick',[])
the grid will also vanish.
But with your code, the grid stays . Thanks
John Barber
2013-5-24
This solution might be overkill, but you can get that effect with my File Exchange program 'oaxes', available here: http://www.mathworks.com/matlabcentral/fileexchange/30018. 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...')
set(get(gca,'YLabel'),'visible','on')
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.
-John
h = axes;
plot(h,rand(10,1));
pos = get(h,'Position');
new_h = axes('Position',pos);
linkaxes([h new_h],'y');
pos(3) = eps; %Edited here
set(new_h,'Position',pos,'XTick',[],'XTickLabel',[]);
set(h,'Visible','off');
Martin
2016-3-24
0 个投票
I solved something similar that way:
set(axis_h,'XColor',axis_h.Parent.Color);
-Martin
This wasn't an option when the question was originally asked, but now you can change the Visible property of the appropriate ruler object that is part of the axes. Compare the axes without the ruler being changed:
ax = axes;
plot(ax, 1:10);
with one that does have the ruler turned off.
figure
ax2 = axes;
plot(ax2, 1:10);
% Get the ruler for the X axis
x = ax2.XAxis;
% Make it invisible
x.Visible = 'off';
1 个评论
Simon
2025-4-4
That still doesn't answer the original question. The question was, could he remove the top axis only and keep the bottom axis. No one has answered this successfully
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

