MATLAB remove ticks on one axis while keeping labels
Asked Answered
A

2

8

I want to make a MATLAB plot that has tick labels but no tick marks on the x axis, but does have tick marks on the y axis. How can I do this?

I can't use

set(gca,'XTick',[])

because this would remove the tick labels. I also can't use

set(gca,'TickLength',[0 0])

because this would remove tick marks on the y axis.

Aton answered 9/10, 2014 at 21:28 Comment(1)
If you’re doing this to get an eps image (or similar vector graphics intended for publication), I suggest using matlab2tikz and then pgfplot in latex to create an eps. (That’s how I usually do it)Senary
H
2

You must use multiple axes to achieve this effect because MATLAB doesn't provide separate TickLength properties for X and Y axes.

Example:

x=linspace(0,4*pi);
y=sin(x);
ax=plotyy(x,y,0,0);
set(ax(1),'XTick',[]);
set(ax(1),'YColor',get(ax(1),'XColor'))
set(ax(2),'TickLength',[0 0]);
set(ax(2),'YTick',[]);

This is a bit hacky, but it works by using the extra y-axis provided in the plotyy() function to keep the x-axis labels with 0 tick length, while still showing the y-ticks from the original y-axis.

Heterolecithal answered 11/10, 2014 at 9:19 Comment(0)
F
1

Starting from MATLAB 2015b you can write:

ax.XAxis.TickLength = [0,0];

and diminish to zero only the X-axis tick length.

Fruition answered 1/1, 2017 at 21:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.