3.1 | 9 ratings Rate this file 26 Downloads (last 30 days) File Size: 31.9 KB File ID: #9815 Version: 1.3
image thumbnail




30 Jan 2006 (Updated )

Change color of grid lines without changing color of axis labels or box

| Watch this File

File Information

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.
-> http://www.mathworks.com/support/solutions/data/1-1PAYMC.html?solution=1-1PAYMC)

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.

grid 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


Prop Listener Add A Callback To Property Value Get/Set Event inspired this file.

MATLAB release MATLAB 7.0.4 (R14SP2)
Other requirements none
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
19 Jun 2013 Becca

Becca (view profile)

Overall it does what I need (had to fix the label bug but that was easy). However, it re-sizes my axes so that they are square. I have to have my plots a specific size/shape (figure('position',[10 10 8.5 8.5*0.8]) in cm). This causes my xlabel to get cut off. Does anybody have a fix for it?

10 Aug 2011 jon smith

i found two errors. it changes the axes titles as well and add it closer to the axis. it also messes up subplots, the axes get completely reconfigured

Comment only
11 Oct 2010 Matthias Pospiech

This script resizes my plot and adds the labels at wrong position in grid color. Therefore it is not applicable for me.

21 Jul 2010 Sebastian Hölz

hey Carey, this works fine for me ... :
>> load clown
>> imagesc(X)
>> gridcolor('w')
>> grid on
You need to be more specific with your problem. Besides ... before giving a crap rating I would spend a minute and maybe ask the author directly for help ...
Just a thought

Comment only
20 Jul 2010 Carey Smith

This did not work will for me with an imagesc plot. (ver. 7.10)
It created ghost versions of my X & Y labels.
Use gridxy.m instead (with the updates I am submitting today).

15 Oct 2009 Ondrej

Ondrej (view profile)

I have problems with zooming. When I use gridcolor I can't zoom the plots in figure, instead the whole box is getting smaller and smaller.

Comment only
15 Oct 2009 Ondrej

Ondrej (view profile)

10 Sep 2009 Junwei Du

For my version(7.8.0),it changes the figure axes size.

26 Jul 2009 abhi mani

SYNTAX: <gridaxeshandle>=cgrid(<colorarg, stylearg, colorargy>)

Comment only
26 Jul 2009 abhi mani

SYNTAX: <gridaxeshandle>=cgrid(<colorarg, stylearg, colorargy>)

10 Jun 2009 Sebastian Hölz

In reply to Joanne Hung and Nitika:
It seems that my update did not make it to the FEX. I have just posted a new version (0.99), which removes the mentioned bugs.

Furthermore, this version also removes all previous restrictions and should now fit nicely into the general Matlab framework. I would recommend everyone with old versions to update, once the new version has been uploaded.


Comment only
04 Jun 2009 Nitika

Nitika (view profile)

Sebastian, I just downloaded your function file and still have the problem that Joanne is mentioning. I have MatlabR2008a.

Comment only
02 Sep 2008 Sebastian Hölz

In reply to Joanne Hung:
I had fixed this bug a while ago, but forgot to update it here on the FEX. It was caused by a call to Matlabs "version"-command, which has somewhat changed its bevavior ... file is updated and should work as expected!

Comment only
17 Jul 2008 Alan B

Can't you just get the current tick values and plot lines of the desired color with endpoints determined by the current limits?

Comment only
17 Jun 2008 Joanne Hung

For my version (v7.5), it does not support "linkaxes". The box changes the color after using the function. If using xlabel or ylabel before grid, there are two labels on one axis and the second label has the color applied on the grid

31 Jan 2006 urs (us) schwarz

with the added help it's very nice and useful
the nasty behavior in certain (anomalous) situations cannot be taken care of easily - but the author provides a valid (and hopefully temporary) workaround

30 Jan 2006 urs (us) schwarz

nice idea
there are some issues that need to be addressed:
- the help section does NOT work at all (wrong indentation of the %-markers)
- once GRIDCOLOR was run for an axis, a subsequent call to PLOT will spit out numerous annoying warnings...

31 Jan 2006

- Fixed help bug. Error mentioned by Urs. Fixes: hold on - after first plot command or Use low level commands ('line' instead of plot). Use gridcolor as last command when creating a plot.

10 Aug 2006

- changed stacking order of "reference" (now bottom) and "gridcolor" (now top) axis
- removed linkaxes command for Matlab 6.5, since it is not included in this release

02 Sep 2008

Update to fix bug in recent Matlab versions.

21 Jan 2009 1.1

09.01.2009 Fixed bug found by Christian S. Hansen. This prevented the axis and labels to be displayed correctly.

10 Jun 2009 1.3

Version 0.99
- No support for Matlab 6.5 or lower anymore
- Should now work as general purpose functions without restrictions
- Removed some bugs

Contact us