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.
To remove the ticks on both the x-axis and y-axis simultaneously, we can pass both left and right attributes simultaneously setting its value to False and pass it as a parameter inside the tick_params() function. It removes the ticks on both x-axis and the y-axis simultaneously.
xticks( ticks ) sets the x-axis tick values, which are the locations along the x-axis where the tick marks appear. Specify ticks as a vector of increasing values; for example, [0 2 4 6] . This command affects the current axes. xt = xticks returns the current x-axis tick values as a vector.
xlabel( txt ) labels the x-axis of the current axes or standalone visualization. Reissuing the xlabel command replaces the old label with the new label. example. xlabel( target , txt ) adds the label to the specified target object.
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.
Starting from MATLAB 2015b you can write:
ax.XAxis.TickLength = [0,0];
and diminish to zero only the X-axis tick length.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With