MATLAB deletes ticks on one axis, keeping marks

I want to create a MATLAB graph that has label labels but no labels on the x axis but has marks on the y axis. How can i do this?

I can not use

set(gca,'XTick',[]) 

because it will remove the tick marks. I also can not use

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

as this will remove the marks on the y axis.

+8
matlab plot matlab-figure
source share
2 answers

To achieve this effect, you must use multiple axes because MATLAB does not provide separate TickLength properties for the 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 using the additional y axis provided by the plotyy() function to save x-axis labels with a length of 0 ticks, while showing y-ticks from the original y-axis.

+2
source share

Starting with MATLAB 2015b you can write:

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

and reduce to zero only the length of the tick along the X axis.

+1
source share

All Articles