How to remove ticks from the x-axis?

1.361 Ansichten (letzte 30 Tage)
Vahid
Vahid am 18 Mär. 2012
Kommentiert: Shaojun Liao am 5 Apr. 2023
Hi everybody,
I am wondering if there is any way to remove the ticks from only one axis, let say x-axis, when you plot a graph. (TickLength applies the changes to both x- and y-axis which is not what I'd like)
Thank you very much in advance, Vahid

Akzeptierte Antwort

bym
bym am 18 Mär. 2012
set(gca,'XTick',[])

Weitere Antworten (3)

Bryan Conklin
Bryan Conklin am 27 Aug. 2019
Bearbeitet: Bryan Conklin am 27 Aug. 2019
h=gca; h.XAxis.TickLength = [0 0];
This will allow you to keep the labels but remove the tick marks on only the x-axis.
  2 Kommentare
Fenglei Gu
Fenglei Gu am 29 Mär. 2022
Thanks!!!! searched for a long time!
Shaojun Liao
Shaojun Liao am 5 Apr. 2023
Thank you so much for helping, hope more people can see it. Because your answer is exactly related to the point.

Melden Sie sich an, um zu kommentieren.


Hossein
Hossein am 18 Okt. 2017
but how to keep the numbers?
  2 Kommentare
Sarah Zinn
Sarah Zinn am 13 Dez. 2017
Bearbeitet: Sarah Zinn am 13 Dez. 2017
I use
set(gca,'TickLength',[0 0])
but it will affect the YTick as well.
Aditya Aji wibowo
Aditya Aji wibowo am 26 Mai 2019
Thank's, it works.

Melden Sie sich an, um zu kommentieren.


Walter Fanka
Walter Fanka am 20 Dez. 2018
set(gca,'TickLength',[0 .01])
% where 0 is the length of ticks on the x-axis and
% .01 is the length on the y-axis.
So in this case, the x-axis is "tickless" :)
  2 Kommentare
LeChat
LeChat am 28 Okt. 2020
This is nice, but would there be a way to remove the ticks only on one side of the graph, and not the one facing it? I would like to have ticks on the main axis but no mirror ticks (I have a box around my graph and I do not want ticks on the other sides of the box). Thank you for your help!
LeChat
LeChat am 28 Okt. 2020
oh actually I found this which works great:
plot(1:10)
% get handle to current axes
a = gca;
% set box property to off and remove background color
set(a,'box','off','color','none')
% create new, empty axes with box but without ticks
b = axes('Position',get(a,'Position'),'box','on','xtick',[],'ytick',[]);
% set original axes as active
axes(a)
% link axes in case of zooming
linkaxes([a b])
from:
https://stackoverflow.com/questions/15553720/matlab-remove-only-top-and-right-ticks-with-leaving-box-on

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by