Search code examples
matlabplothidecustomizationmatlab-figure

How to hide the axes but keep the grid?


If we have a figure

plot(x, y);
grid on;

We get something like this

enter image description here

But now, I wish to hide the axis, so I tried the commands below:

axis off
set(gca,'xtick',[])
set(gca,'ytick',[])
set(gca,'visible','off')

Together they successfully hid the axis, but the grid was also deleted!

set(gca, 'xticklabel', []) can hide the label, but not the axis.

So, how do I hide the axis, ticks and labels, leaving only the plot and grid?


Solution

  • You can set Xcolor and Ycolor to none so the axis won't be displayed:

    %dummy data
    x = [-5:.1:5];
    y = normpdf(x,0,1);
    plot(x, y);
    
    %grid on
    grid on;
    
    %Set the axis color to none.
    set(gca,'XColor','none','Ycolor','none')
    

    enter image description here