File Exchange

image thumbnail


version (2.06 KB) by Andri M. Gretarsson
chose the color and style of grid lines in a figure

1 Download

Updated 01 Sep 2006

No License

Creates a new set of axes containing the colored grid, immediately behind the current axes. To make the axes with the grid visible, the current axes are made transparent and the current axes grid is removed. If any colored grid axes are in use when this function is called, it first deletes these old grids, before adding new cgrid axes. That way figure children don't multiply.

<gridaxishandle>=cgrid(<colorarg, stylearg, colorargy>)

Cite As

Andri M. Gretarsson (2020). cgrid (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

M. B.


I tried cgrid, there is only on Problem. I used a filled contourplot, the grid is below and invisible. Hope you can fix it...
But its a realy nice Idea.

John D'Errico

A nice idea.

While I am the last person to want to disagree with a somehat nonstandard commenting practice, there are some useful standards. For example, the matlab function lookfor uses the H1 line in each function for its behavior.

The header line in cgrid is:

See Loren's blog for more discussion on commenting a fuction.

My only other comment is on the use of arguments for linestyle, color, etc. I'd suggest that property/value pairs would be more logical here, to be consistent with the rest of matlab. An advantage of property/value pairs is that it is so much easier in the future to enhance your code, if one day you decide to add other features, perhaps line thickness or transparency, etc. You also do not need to worry about what order the arguments appear in.

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux