Updated 10 Jun 2009
Use this function to change the color of gridlines to a color different to the label and box color, which is currently not implemented in Matlab.
The general syntax for a call is:
gridcolor([ax1, ax2, ...], c_x, c_y, c_z)
Here ax1, ... are handles to existing axes (optional argument) and c_xyz are color specifications (e.g. 'r' or [1 0 0], also optional). If no axis handle is supplied, the call goes to the current axis (gca), if no color is supplied a standard color, which is defined in the first executable line of the file, is used.
The function should be called after the plot has been created and the grid has been turned on.
gridcolor([1 0 0], 'b')
This function is no longer tested for Matlab 6.5 or lower and will most likely not work for these versions. It should run on Matlab 7.0 or higher.
For further examples please refer to the examples in the header of the file.
PS.: I have included some lines from Yair Altmans "PropListener" example
Sebastian Hölz (2023). gridcolor (https://www.mathworks.com/matlabcentral/fileexchange/9815-gridcolor), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
- MATLAB > Graphics > Formatting and Annotation > Axes Appearance > Limits, Ticks, and Grids > Grid Lines, Tick Values, and Labels >
Inspired by: PropListener - add a callback to property value get/set event
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
09.01.2009 Fixed bug found by Christian S. Hansen. This prevented the axis and labels to be displayed correctly.
Found another small bug ...