Search code examples
matlabmatlab-figure

Remove only the ticks in plot in MATLAB


Is it possible to only remove the ticks in plots?

enter image description here


Solution

  • You can use the xticks function (or the statement set(gca, 'xtick', ...)) to choose which ones you want to display. Doing so will also affect the tick labels, because each tick has an associated label:

    plot(1:8)
    xticks([1 2 3 5 6 8]) % remove ticks and labels at 4 and 7
    

    enter image description here

    If you want to remove all ticks from the axis but keep (some or all) labels, you can set the tick length to 0, which doesn't affect the labels:

    plot(1:8)
    xticks([1 2 3 5 6 8]) % remove ticks and labels at 4 and 7
    set(get(gca, 'XAxis'), 'TickLength', [0 0]) % make all ticks have size 0
    

    enter image description here