rmc logo

Dr.-Ing. Thomas Hulin ‒ useful stuff

Back to Thomas Hulin's Homepage


Nice Matlab Grid

Note: I programmed this in function 2014, i.e. before Matlab introduced their more beautiful grid function.

As I am using Matlab for some of my research work, I wondered if there is a way to obtain nice grids for the plots that I am using in my scientific publications. The standard Matlab grid function creates only a black grid of black dotted lines, which really does not look nice to my opinion. Unfortunately, I could not find any satisfactory alternative in the internet. Thus, I decided to implement an own grid function that draws a pretty grid with the following properties:

  • The grid lines are made of dashed lines.
  • In the crossing point of two ticks (XTick and YTick) a horizontal and a vertical dash form a plus sign.
  • Between two pluses a variable number of dashes is drawn that fits in the space.
  • The line-properties (e.g., Color and LineWidth) can be parameterized.

This is how the result may look like:

Example plot with the dlrGrid function (Image: DLR, CC-BY).


You can download and use the dlrGrid function for free (BSD 2-Clause License). Before using it, you must rename the file to "dlrGrid.m" (it was not possible on this server to upload files with "m" as suffix). Hint: type set(gca,'Box','off') to turn off the black box around the current Matlab axis.

If you like this function, I would be happy if you could send me an e-mail, if possible with a screenshot of your figure. If you wish, I post your sceenshot on this page.

You may also be interested in having a look at my journal article on "Passivity and Stability Boundaries for Haptic Systems with Time Delay" (IEEE Xplore account required), in which all figures were generated using this function.

Example Images

Short Description
An empty Matlab figure with a gray dashed grid generated by the dlrGrid function.

Thomas Hulin, DLR , Sep. 2014, CC-BY

Short Description
An empty Matlab figure with a light blue dashed grid generated by the dlrGrid function with the following parameters:
>> set(gca,'YTick',[0:0.25:1]);
>> dlrGrid(gca,'Color',[0.5 0.8 1.0],'LineWidth',1)

Thomas Hulin, DLR , Sep. 2014, CC-BY

Short Description
Step response of a linear system. The signal settles (2% threshold band) after 5.139 sampling periods.

Thomas Hulin, DLR , Sep. 2014, CC-BY



Zuletzt aktualisiert: Dienstag, 29. September 2020 von Dr.-Ing. Thomas Hulin