8
votes

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.

2
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)vindarmagnus

2 Answers

2
votes

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.

1
votes

Starting from MATLAB 2015b you can write:

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

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