A graticule is a set of reference lines on a map that help orient a map reader. They are often set at, and labeled, with the coordinates. The tricky part about using graticules, however, is projections. If you don't make them correctly, instead of smooth curves between the line intersections, you get awkward unusual shapes (mostly straight lines). The default QGIS graticule creator is not projection-friendly, so in this recipe, you'll see an add-on processing algorithm that does this. This recipe is about ensuring you get nice, smooth, and properly-labeled graticules.
You don't really need much for this recipe other than a bounding box and a coordinate interval that you want to space the lines at. Usually, these will be in Latitude, Longitude WGS 84 (EPSG:4326), and decimal degrees, respectively, since the whole point of a graticule is to add reference lines that help orient a user.
You will see something like the following screenshot:






Graticules are basically line layers (though sometimes they are also polygons). If you draw a grid with nodes only at the points where two lines intersect, you can easily see how distorting the grid will lead to blocky shapes. The key to smooth graticules is adding additional line nodes in between the intersections (that is, increase the node density).
It's important to note that, when using projections that don't cover the whole world (for example, polar or stereographic projections), pick bounding box values that fall within the projection limits; otherwise, you may get errors when trying to reproject.
The primary advantages of graticules in the main map canvas are that you can use them as references while working in QGIS, include them in web and digital maps, and have full control of the labels and symbology. The method used here differs from other graticule (grid) tools in QGIS because it focuses on putting Latitude/Longitude lines with smooth curves as references into any projection. Other grid tools focus more on making regular squares across a map to subdivide a region.
The main advantages of the print composer method (next recipe) are its ability to make multiple coordinate systems easily and to add tick marks around the outside edge of a map. Tick marks are what you commonly see on navigation-oriented maps, such as USGS Topo quads, and other printed maps.
Lines graticule (aka Pygraticule) can also be used as a pure Python script; for updates and more information, refer to https://github.com/wildintellect/pyGraticule.
To learn how to write your own processing toolbox algorithms, refer to the Writing processing algorithms recipe in Chapter 11, Extending QGIS.