Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

How can I change the gridline color without changing the tick and tick label colors?


Date Last Modified: Monday, September 21, 2009
Solution ID:   1-1PAYMC
Product:   MATLAB
Reported in Release:   R14SP1
Fixed in Release:   R2008a
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How can I change the gridline color without changing the tick and tick label colors?

Problem Description:

When I execute the following lines of code:
ezplot('x')
grid on
set(gca,'Xcolor','r')
the color of the x-axis gridlines, x tick-marks and x tick-labels all become red.

I would like to selectively change the color of the gridlines alone, without changing the color of the x tick-marks and x tick-labels.

Solution:

The gridline color cannot be changed without affecting the tick-mark and tick-label colors.

However, you can work around this issue by copying the existing axes and using it as a mask. The copy will lay over the existing axes, without gridlines, and using the default black for the axes tick-marks and tick-labels. Try executing the following after creating your plot with the colored gridlines:
c_axes = copyobj(gca,gcf);
set(c_axes, 'color', 'none', 'xcolor', 'k', 'xgrid', 'off', 'ycolor','k', 'ygrid','off');
After executing the above code, the color of the x-axis gridlines remain red, whereas the x tick-marks and x tick-labels are black.

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page