3.6

3.6 | 6 ratings Rate this file 225 downloads (last 30 days) File Size: 31.87 KB File ID: #9815

gridcolor

by Sebastian Hölz

 

30 Jan 2006 (Updated 10 Jun 2009)

Code covered by BSD License  

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

Download Now | Watch this File

File Information
Description

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.

Example:
plot(1,1)
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.

Cheers
Sebi

PS.: I have included some lines from Yair Altmans "PropListener" example

MATLAB release MATLAB 7.0.4 (R14SP2)
Other requirements none
Zip File Content  
Other Files gridcolor.m,
gridcolorExample.png,
license.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (12)
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...
us

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
us

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

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?

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!

04 Jun 2009 Nitika

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

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.

Cheers
Sebastian

26 Jul 2009 abhi mani

SYNTAX: <gridaxeshandle>=cgrid(<colorarg, stylearg, colorargy>)
gridaxishandle=cgrid('g-');

26 Jul 2009 abhi mani

SYNTAX: <gridaxeshandle>=cgrid(<colorarg, stylearg, colorargy>)
gridaxishandle=cgrid('g-');

10 Sep 2009 Junwei Du

  

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

15 Oct 2009 Ondrej  
15 Oct 2009 Ondrej

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.

Please login to add a comment or rating.
Updates
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.

02 Sep 2008

Found another small bug ...

21 Jan 2009

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

10 Jun 2009

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

Tag Activity for this File
Tag Applied By Date/Time
annotation Sebastian Hölz 22 Oct 2008 08:14:00
customization Sebastian Hölz 22 Oct 2008 08:14:00
grid color Sebastian Hölz 22 Oct 2008 08:14:00
axis labels Sebastian Hölz 22 Oct 2008 08:14:00
plot annotation Sebastian Hölz 22 Oct 2008 08:14:00
graphics Sebastian Hölz 22 Oct 2008 08:14:00
box color Sebastian Hölz 22 Oct 2008 08:14:00
matlab 7 Sebastian Hölz 10 Jun 2009 11:14:36
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com